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(litellm): gate the gpt-5.4+ responses bridge on function tools specifically
Tin Chi Lo7276f44b1db7
diff --git a/litellm/main.py b/litellm/main.pyindex 43d021ebe8b..8a9e0e37ace 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -1022,14 +1022,20 @@ def responses_api_bridge_check(# ``reasoningSummary`` in ``extra_body``) must be bridged; Chat Completions rejects# those keys.#- # - gpt-5.4+: function tools with reasoning active must be bridged. OpenAI enables+ # - gpt-5.4+: FUNCTION tools with reasoning active must be bridged. OpenAI enables# reasoning by default for these models (unset reasoning_effort means medium- # server-side), and Chat Completions rejects tools whenever reasoning is on- # ("Function tools with reasoning_effort are not supported ... use /v1/responses- # or set reasoning_effort to 'none'"), so only an explicit ``"none"`` keeps the- # request chat-servable.+ # server-side), and Chat Completions rejects function tools whenever reasoning is+ # on ("Function tools with reasoning_effort are not supported ... use+ # /v1/responses or set reasoning_effort to 'none'"), so only an explicit+ # ``"none"`` keeps the request chat-servable. Custom (grammar) tools are served+ # natively by Chat Completions with reasoning on, so custom-only requests stay on+ # chat and keep their native custom tool_call response shape.# - Older GPT-5 names (e.g. ``gpt-5``, ``gpt-5.1``): bridge only when a reasoning# summary alias is present with ``reasoning_effort`` (tools alone stay on chat).+ has_function_tool = any(+ (tool.get("type") == "function" if isinstance(tool, dict) else getattr(tool, "type", None) == "function")+ for tool in (tools or [])+ )if (custom_llm_provider in ("openai", "azure")and model_info.get("mode") != "responses"@@ -1037,7 +1043,9 @@ def responses_api_bridge_check(and not OpenAIGPT5Config.is_model_gpt_5_search_model(model)and ((reasoning_effort is not None and reasoning_summary is not None)- or (OpenAIGPT5Config.is_model_gpt_5_4_plus_model(model) and tools and reasoning_effort != "none")+ or (+ OpenAIGPT5Config.is_model_gpt_5_4_plus_model(model) and has_function_tool and reasoning_effort != "none"+ ))):model_info["mode"] = "responses"diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.pyindex b4f94177f7d..4a0ec04bed1 100644--- a/tests/test_litellm/test_main.py+++ b/tests/test_litellm/test_main.py@@ -889,6 +889,65 @@ def test_responses_api_bridge_check_reasoning_none_with_summary_still_routes_to_assert model_info.get("mode") == "responses"+def test_responses_api_bridge_check_gpt_5_4_custom_tools_only_stays_chat():+ """+ Chat Completions serves custom (grammar) tools natively with reasoning on; only+ FUNCTION tools trigger the OpenAI rejection. Custom-only requests must stay on chat+ so responses keep the native custom tool_call shape instead of the bridge's+ function-shaped mapping.+ """+ from litellm.main import responses_api_bridge_check++ with patch("litellm.main._get_model_info_helper") as mock_get_model_info:+ mock_get_model_info.return_value = {"max_tokens": 128000}+ model_info, model = responses_api_bridge_check(+ model="gpt-5.6",+ custom_llm_provider="openai",+ tools=[{"type": "custom", "custom": {"name": "ApplyPatch", "description": "V4A patch"}}],+ reasoning_effort=None,+ )++ assert model == "gpt-5.6"+ assert model_info.get("mode") != "responses"+++def test_responses_api_bridge_check_gpt_5_4_mixed_function_and_custom_tools_routes_to_responses():+ """One function tool in the mix is enough to make chat unservable with reasoning on."""+ from litellm.main import responses_api_bridge_check++ with patch("litellm.main._get_model_info_helper") as mock_get_model_info:+ mock_get_model_info.return_value = {"max_tokens": 128000}+ model_info, model = responses_api_bridge_check(+ model="gpt-5.6",+ custom_llm_provider="openai",+ tools=[+ {"type": "custom", "custom": {"name": "ApplyPatch"}},+ {"type": "function", "function": {"name": "shell"}},+ ],+ reasoning_effort=None,+ )++ assert model == "gpt-5.6"+ assert model_info.get("mode") == "responses"+++def test_responses_api_bridge_check_gpt_5_4_flat_function_tool_routes_to_responses():+ """Responses-style flat function tool defs still count as function tools."""+ from litellm.main import responses_api_bridge_check++ with patch("litellm.main._get_model_info_helper") as mock_get_model_info:+ mock_get_model_info.return_value = {"max_tokens": 128000}+ model_info, model = responses_api_bridge_check(+ model="gpt-5.6",+ custom_llm_provider="openai",+ tools=[{"type": "function", "name": "shell", "parameters": {"type": "object"}}],+ reasoning_effort=None,+ )++ assert model == "gpt-5.6"+ assert model_info.get("mode") == "responses"++def test_responses_api_bridge_check_older_gpt_5_tools_without_reasoning_stays_chat():"""Pre-5.4 GPT-5 names keep the old boundary: tools alone never bridge."""from litellm.main import responses_api_bridge_check