The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(responses-bridge): preserve reasoning merge order when assistant already has reasoning_content
HarryZhou3a77556dc146
diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.pyindex 5d3ed0477e3..0604c3636ff 100644--- a/litellm/responses/litellm_completion_transformation/transformation.py+++ b/litellm/responses/litellm_completion_transformation/transformation.py@@ -628,7 +628,7 @@ class LiteLLMCompletionResponsesConfig:combined = "\n".join(pending_reasoning)existing = _reasoning_text(msg)if existing:- combined = existing + "\n" + combined+ combined = combined + "\n" + existingif isinstance(msg, dict):msg["reasoning_content"] = combinedelse:diff --git a/tests/test_litellm/responses/litellm_completion_transformation/test_reasoning_input_item_preservation.py b/tests/test_litellm/responses/litellm_completion_transformation/test_reasoning_input_item_preservation.pyindex 5fcd4df3ff8..ecc024b7d04 100644--- a/tests/test_litellm/responses/litellm_completion_transformation/test_reasoning_input_item_preservation.py+++ b/tests/test_litellm/responses/litellm_completion_transformation/test_reasoning_input_item_preservation.py@@ -129,6 +129,18 @@ class TestReasoningInputItemMerging:assert messages[0]["reasoning_content"] == "I should look this up"assert len(messages[0]["tool_calls"]) == 1+ def test_reasoning_merged_into_assistant_with_existing_reasoning_content(self):+ """Old reasoning precedes existing reasoning on the target assistant turn."""+ messages = LiteLLMCompletionResponsesConfig._merge_reasoning_only_assistant_messages(+ [+ {"role": "assistant", "content": None, "reasoning_content": "old reasoning"},+ {"role": "assistant", "content": "The answer.", "reasoning_content": "new reasoning"},+ ]+ )+ assert len(messages) == 1+ assert messages[0]["content"] == "The answer."+ assert messages[0]["reasoning_content"] == "old reasoning\nnew reasoning"+class TestNonReasoningInputItemUnchanged:"""Non-reasoning items still flow through the existing branches."""