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
require an incomplete reason before overriding finish_reason
mateo-berri16bba154347d
diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.pyindex c6d5b04d370..6103b1bf484 100644--- a/litellm/completion_extras/litellm_responses_transformation/transformation.py+++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py@@ -836,8 +836,8 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):handle_raw_dict_callback=self._handle_raw_dict_response_item,)- response_is_incomplete: Final = (- raw_response.status == "incomplete" or raw_response.incomplete_details is not None+ response_is_incomplete: Final = raw_response.status == "incomplete" or (+ raw_response.incomplete_details is not None and raw_response.incomplete_details.reason is not None)if len(choices) == 0 and not response_is_incomplete:diff --git a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.pyindex 315a8c6ed95..382b41807d4 100644--- a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py+++ b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py@@ -3,7 +3,7 @@ import jsonimport osimport sysimport unittest-from typing import TYPE_CHECKING, List, Optional, Tuple+from typing import TYPE_CHECKING, List, Literal, Optional, Tuplefrom unittest.mock import ANY, MagicMock, Mock, patchimport httpx@@ -3497,6 +3497,8 @@ async def test_acompletion_bridge_normalizes_tool_choice_on_the_wire(def _make_incomplete_responses_api_response(incomplete_reason: Optional[str],output: "List[ResponseOutputItem]",+ status: Literal["completed", "incomplete"] = "incomplete",+ empty_incomplete_details: bool = False,) -> "ResponsesAPIResponse":from litellm.types.llms.openai import (InputTokensDetails,@@ -3509,7 +3511,11 @@ def _make_incomplete_responses_api_response(id="resp_incomplete",created_at=1760144904,error=None,- incomplete_details={"reason": incomplete_reason} if incomplete_reason else None,+ incomplete_details=(+ {"reason": incomplete_reason}+ if incomplete_reason is not None or empty_incomplete_details+ else None+ ),instructions=None,metadata={},model="gpt-5.6-sol",@@ -3523,7 +3529,7 @@ def _make_incomplete_responses_api_response(max_output_tokens=16,previous_response_id=None,reasoning={"effort": "high", "summary": None},- status="incomplete",+ status=status,text={"format": {"type": "text"}, "verbosity": "medium"},truncation="disabled",usage=ResponseAPIUsage(@@ -3624,6 +3630,32 @@ def test_transform_response_zero_choices_not_incomplete_still_raises():_call_transform_response(handler, raw_response)+def test_transform_response_completed_with_reasonless_incomplete_details_keeps_stop():+ from openai.types.responses import ResponseOutputMessage, ResponseOutputText++ handler = LiteLLMResponsesTransformationHandler()+ output_message = ResponseOutputMessage(+ id="msg_complete",+ content=[+ ResponseOutputText(+ annotations=[], text="full answer", type="output_text", logprobs=[]+ )+ ],+ role="assistant",+ status="completed",+ type="message",+ )+ raw_response = _make_incomplete_responses_api_response(+ None, [output_message], status="completed", empty_incomplete_details=True+ )++ result = _call_transform_response(handler, raw_response)++ assert len(result.choices) == 1+ assert result.choices[0].finish_reason == "stop"+ assert result.choices[0].message.content == "full answer"++def test_transform_response_incomplete_partial_text_overrides_finish_reason_to_length():from openai.types.responses import ResponseOutputMessage, ResponseOutputText