Skip to content

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]

Merge remote-tracking branch 'origin/main' into litellm_invalid_tool_choice_400

mateo-berri2c2aa5df1195
diff --cc tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py
index 3950fd549ef,c66133ed5f1..25920c2351c
--- a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py
+++ b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py
@@@ -4908,16 -4940,63 +4940,77 @@@ class TestStreamingSnapshotItemIds
assert reasoning_items[0].id == streamed_event.item_id
+ def test_transform_chat_completion_response_incomplete_details():
+ from litellm.types.llms.openai import IncompleteDetails
+
+ resp_length = ModelResponse(
+ id="resp-length",
+ choices=[Choices(index=0, finish_reason="length", message=Message(content="cutoff", role="assistant"))],
+ model="gpt-4o",
+ )
+ result_length = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(
+ request_input="test prompt",
+ responses_api_request={},
+ chat_completion_response=resp_length,
+ )
+ assert result_length.status == "incomplete"
+ assert result_length.incomplete_details is not None
+ assert result_length.incomplete_details.reason == "max_output_tokens"
+
+ resp_filter = ModelResponse(
+ id="resp-filter",
+ choices=[Choices(index=0, finish_reason="content_filter", message=Message(content=None, role="assistant"))],
+ model="gpt-4o",
+ )
+ result_filter = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(
+ request_input="test prompt",
+ responses_api_request={},
+ chat_completion_response=resp_filter,
+ )
+ assert result_filter.status == "incomplete"
+ assert result_filter.incomplete_details is not None
+ assert result_filter.incomplete_details.reason == "content_filter"
+
+ resp_refusal = ModelResponse(
+ id="resp-refusal",
+ choices=[Choices(index=0, finish_reason="refusal", message=Message(content=None, role="assistant"))],
+ model="gpt-4o",
+ )
+ result_refusal = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(
+ request_input="test prompt",
+ responses_api_request={},
+ chat_completion_response=resp_refusal,
+ )
+ assert result_refusal.status == "incomplete"
+ assert result_refusal.incomplete_details is not None
+ assert result_refusal.incomplete_details.reason == "content_filter"
+
+ existing_details = IncompleteDetails(reason="content_filter")
+ resp_existing = ModelResponse(
+ id="resp-existing",
+ choices=[Choices(index=0, finish_reason="length", message=Message(content="cutoff", role="assistant"))],
+ model="gpt-4o",
+ )
+ resp_existing.incomplete_details = existing_details
+ result_existing = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(
+ request_input="test prompt",
+ responses_api_request={},
+ chat_completion_response=resp_existing,
+ )
+ assert result_existing.status == "incomplete"
+ assert result_existing.incomplete_details == existing_details
+
++
[email protected]("stream", [True, False])
+async def test_bridge_rejects_untranslatable_tool_choice_with_a_400(stream: bool):
+ with pytest.raises(litellm.BadRequestError) as exc_info:
+ await litellm.aresponses(
+ model="anthropic/claude-haiku-4-5",
+ input="Which fruit is red?",
+ tools=[{"type": "function", "name": "lookup_fruit", "parameters": {"type": "object"}}],
+ tool_choice={"type": "file_search"},
+ stream=stream,
+ api_key="sk-unused",
+ )
+ assert exc_info.value.status_code == 400
+ assert "tool_choice={'type': 'file_search'}" in str(exc_info.value)
diff --cc tests/test_litellm/test_main.py
index 81ad161772e,bd115c699d5..3c90675d04d
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@@ -3852,15 -3945,25 +3945,39 @@@ def test_bridged_responses_with_openai_
assert {k: request.headers[k] for k in FORWARDED_CLIENT_HEADERS} == FORWARDED_CLIENT_HEADERS
+ @pytest.mark.parametrize("http2_on", [True, False])
+ def test_aiohttp_openai_warns_only_when_http2_enabled(
+ monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, http2_on: bool
+ ):
+ from litellm.main import base_llm_aiohttp_handler
+
+ monkeypatch.setattr(litellm, "http2", http2_on)
+ monkeypatch.delenv("LITELLM_HTTP2", raising=False)
+
+ handler_completion: Final = MagicMock(return_value=MagicMock())
+ monkeypatch.setattr(base_llm_aiohttp_handler, "completion", handler_completion)
+
+ with caplog.at_level(logging.WARNING, logger="LiteLLM"):
+ litellm.completion(
+ model="aiohttp_openai/gpt-4o",
+ messages=[{"role": "user", "content": "hi"}],
+ api_key="sk-test",
+ )
+
+ assert handler_completion.called
+ warned: Final = "aiohttp_openai/ always uses aiohttp" in caplog.text
+ assert warned is http2_on
++
++
[email protected]("tool_choice", [{"type": "bogus"}, {"name": "lookup_fruit"}, {"type": "file_search"}])
+def test_completion_rejects_untranslatable_tool_choice_with_a_400(tool_choice):
+ with pytest.raises(litellm.BadRequestError) as exc_info:
+ litellm.completion(
+ model="anthropic/claude-haiku-4-5",
+ messages=[{"role": "user", "content": "Which fruit is red?"}],
+ tools=[{"type": "function", "function": {"name": "lookup_fruit", "parameters": {"type": "object"}}}],
+ tool_choice=tool_choice,
+ api_key="sk-unused",
+ )
+ assert exc_info.value.status_code == 400
+ assert f"tool_choice={tool_choice}" in str(exc_info.value)