diff --git a/pageindex/cloud_api.py b/pageindex/cloud_api.py index a4b1039..b8f499a 100644 --- a/pageindex/cloud_api.py +++ b/pageindex/cloud_api.py @@ -147,6 +147,12 @@ class LegacyCloudAPI: payload["temperature"] = temperature if enable_citations: payload["enable_citations"] = enable_citations + # Forward stream_metadata so the wire request matches the caller's intent + # (and stays correct if the server ever gates metadata chunks behind it), + # mirroring the modern CloudBackend which always sends it. It only affects + # streaming responses, where it selects the raw dict-chunk parser below. + if stream_metadata: + payload["stream_metadata"] = stream_metadata response = self._request( "POST", diff --git a/tests/test_legacy_sdk_contract.py b/tests/test_legacy_sdk_contract.py index 2471f1c..44a9938 100644 --- a/tests/test_legacy_sdk_contract.py +++ b/tests/test_legacy_sdk_contract.py @@ -238,7 +238,10 @@ def test_chat_completions_stream_metadata_returns_raw_chunks(monkeypatch): )) assert chunks == [{"object": "chat.completion.chunk"}] - assert "stream_metadata" not in calls[0]["json"] + # stream_metadata must be forwarded to the server so the wire request matches + # the caller's intent (and mirrors the modern CloudBackend), not kept as a + # client-only parser switch. + assert calls[0]["json"]["stream_metadata"] is True def test_chat_completions_stream_errors_are_pageindex_api_error(monkeypatch):