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): satisfy type-discipline budget in reasoning merge
HarryZhou438c1850fe12
diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.pyindex 2c506d4a4c7..e3e62ab3c55 100644--- a/litellm/responses/litellm_completion_transformation/transformation.py+++ b/litellm/responses/litellm_completion_transformation/transformation.py@@ -561,13 +561,13 @@ class LiteLLMCompletionResponsesConfig:@staticmethoddef _merge_reasoning_only_assistant_messages(- messages: list[+ messages: list[ # mutable-ok: input sequenceAllMessageValues| GenericChatCompletionMessage| ChatCompletionMessageToolCall| ChatCompletionResponseMessage],- ) -> list[+ ) -> list[ # mutable-ok: fresh merged listAllMessageValues | GenericChatCompletionMessage | ChatCompletionMessageToolCall | ChatCompletionResponseMessage]:"""@@ -591,9 +591,9 @@ class LiteLLMCompletionResponsesConfig:def _reasoning_text(msg: object) -> str | None:if isinstance(msg, dict):- value = msg.get("reasoning_content")+ value = msg.get("reasoning_content") # rebind-ok: branch lookupelse:- value = getattr(msg, "reasoning_content", None)+ value = getattr(msg, "reasoning_content", None) # rebind-ok: branch lookupreturn value if isinstance(value, str) and value else Nonedef _content(msg: object) -> object | None:@@ -606,13 +606,13 @@ class LiteLLMCompletionResponsesConfig:return msg.get("tool_calls")return getattr(msg, "tool_calls", None)- merged: list[+ merged: list[ # mutable-ok: accumulator # rebind-ok: accumulatorAllMessageValues| GenericChatCompletionMessage| ChatCompletionMessageToolCall| ChatCompletionResponseMessage- ] = []- pending_reasoning: list[str] = []+ ] = [] # mutable-ok: accumulator+ pending_reasoning: list[str] = [] # mutable-ok: accumulator # rebind-ok: accumulatorfor msg in messages:if (@@ -633,11 +633,11 @@ class LiteLLMCompletionResponsesConfig:msg["reasoning_content"] = combinedelse:setattr(msg, "reasoning_content", combined) # noqa: B010- pending_reasoning = []+ pending_reasoning = [] # mutable-ok: reset accumulatorelif pending_reasoning:# Not followed by an assistant message — keep the reasoning# standalone instead of dropping it.- merged.extend(+ merged.extend( # mutable-ok: append reasoning messages[ChatCompletionResponseMessage(role="assistant",@@ -647,11 +647,11 @@ class LiteLLMCompletionResponsesConfig:for text in pending_reasoning])- pending_reasoning = []+ pending_reasoning = [] # mutable-ok: reset accumulatormerged.append(msg)- merged.extend(+ merged.extend( # mutable-ok: append trailing reasoning[ChatCompletionResponseMessage(role="assistant",@@ -1137,13 +1137,15 @@ class LiteLLMCompletionResponsesConfig:# to be replayed as `reasoning_content` on an assistant message, not as# visible `content` (prompt pollution) and not dropped (DeepSeek V4# rejects multi-turn requests with a missing `reasoning_content`).- reasoning_text = LiteLLMCompletionResponsesConfig._extract_reasoning_text_from_input_item(input_item)+ reasoning_text = LiteLLMCompletionResponsesConfig._extract_reasoning_text_from_input_item( # rebind-ok: extraction result+ input_item+ )if not reasoning_text:# No plaintext reasoning is available (e.g. encrypted_content only).# Chat-completions providers cannot consume opaque encrypted blobs,# so skip the item instead of polluting the prompt.- return []- return [+ return [] # mutable-ok: empty drop result+ return [ # mutable-ok: single message resultChatCompletionResponseMessage(role="assistant",content=None,@@ -1181,7 +1183,7 @@ class LiteLLMCompletionResponsesConfig:if isinstance(content, str) and content.strip():return contentif isinstance(content, list):- text_parts: list[str] = []+ text_parts: list[str] = [] # mutable-ok: text accumulator # rebind-ok: text accumulatorfor block in content:if not isinstance(block, Mapping):continue@@ -1196,7 +1198,7 @@ class LiteLLMCompletionResponsesConfig:summary: Final[object] = input_item.get("summary")if isinstance(summary, list):- text_parts = []+ text_parts = [] # mutable-ok: text accumulator # rebind-ok: text accumulatorfor block in summary:if not isinstance(block, Mapping):continue