diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index f632317d9a8..e6f8251d4fd 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -10049,6 +10049,7 @@ def _fast_serialize_simple_model_response_stream( "annotations", "reasoning_content", "thinking_blocks", + "reasoning_items", "provider_specific_fields", "refusal", ) diff --git a/tests/unit/proxy/proxy_server/test_streaming_helpers.py b/tests/unit/proxy/proxy_server/test_streaming_helpers.py index 9a3516d20d6..ebbf2326fd0 100644 --- a/tests/unit/proxy/proxy_server/test_streaming_helpers.py +++ b/tests/unit/proxy/proxy_server/test_streaming_helpers.py @@ -553,6 +553,14 @@ def test_fast_serialize_simple_model_response_stream_with_usage_returns_none_inv assert _fast_serialize_simple_model_response_stream(chunk) is None +def test_fast_serialize_simple_model_response_stream_with_reasoning_items_returns_none(): + chunk = _simple_chunk(content="") + chunk.choices[0].delta.reasoning_items = [ + {"id": "rs_abc", "type": "reasoning", "encrypted_content": "ENCRYPTED-BLOB"} + ] + assert _fast_serialize_simple_model_response_stream(chunk) is None + + # --------------------------------------------------------------------------- # _serialize_streaming_chunk # --------------------------------------------------------------------------- @@ -576,6 +584,30 @@ def test_serialize_streaming_chunk_simple_uses_fast_path_bytes(): } +def test_serialize_streaming_chunk_preserves_reasoning_items(): + chunk = _simple_chunk(content="") + chunk.choices[0].delta.reasoning_items = [ + {"id": "rs_abc", "type": "reasoning", "encrypted_content": "ENCRYPTED-BLOB"} + ] + payload: Final = json.loads(_serialize_streaming_chunk(chunk)) + assert payload == { + "id": "chatcmpl-test", + "created": 0, + "model": "gpt-4", + "object": "chat.completion.chunk", + "choices": [ + { + "index": 0, + "delta": { + "role": "assistant", + "content": "", + "reasoning_items": [{"id": "rs_abc", "type": "reasoning", "encrypted_content": "ENCRYPTED-BLOB"}], + }, + } + ], + } + + def test_serialize_streaming_chunk_invalid_input_raises_attribute_error(): """The helper is typed as ``BaseModel`` — handing it a plain dict trips the attribute-access path (no ``model_dump_json``)."""