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] Replace cast with proper typing for reasoning_items
Yuneng Jiang310d61ba70a7
diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.pyindex fded88c3ec5..a387418ef55 100644--- a/litellm/completion_extras/litellm_responses_transformation/transformation.py+++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py@@ -56,6 +56,16 @@ if TYPE_CHECKING:)+def _get_reasoning_items(+ msg: "AllMessageValues",+) -> List[ChatCompletionReasoningItem]:+ """Extract reasoning_items from a message dict with proper typing."""+ items = msg.get("reasoning_items") # type: ignore[union-attr]+ if items:+ return items # type: ignore[return-value]+ return []++def _build_reasoning_item(item_id: str,encrypted_content: Optional[str],@@ -86,7 +96,7 @@ def _build_reasoning_item(}-def _reasoning_item_to_response_input(r_item: Dict[str, Any]) -> Dict[str, Any]:+def _reasoning_item_to_response_input(r_item: Union[ChatCompletionReasoningItem, Dict[str, Any]]) -> Dict[str, Any]:"""Convert a stored ChatCompletionReasoningItem back to a Responses API input item."""r_input: Dict[str, Any] = {"type": "reasoning",@@ -246,7 +256,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):})elif role == "assistant" and tool_calls and isinstance(tool_calls, list):- for r_item in cast(list, msg.get("reasoning_items") or []):+ for r_item in _get_reasoning_items(msg):input_items.append(_reasoning_item_to_response_input(r_item))for tool_call in tool_calls:function = tool_call.get("function")@@ -264,7 +274,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):raise ValueError(f"tool call not supported: {tool_call}")elif content is not None:if role == "assistant":- for r_item in cast(list, msg.get("reasoning_items") or []):+ for r_item in _get_reasoning_items(msg):input_items.append(_reasoning_item_to_response_input(r_item))input_items.append({diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex 9e669655761..80b6190db8f 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -747,6 +747,7 @@ class ChatCompletionAssistantMessage(OpenAIChatCompletionAssistantMessage, totalthinking_blocks: Optional[List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]]]+ reasoning_items: Optional[List[ChatCompletionReasoningItem]]class ChatCompletionToolMessage(TypedDict):