From 4d35fdde59082b08420d5a8e17a4d30e92e1b284 Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Mon, 6 Jul 2026 23:32:48 -0400 Subject: [PATCH 1/2] fix(github_copilot): route gpt-5.4+ tool calls with reasoning_effort to /v1/responses github_copilot/gpt-5.4 with function tools and reasoning_effort failed at the provider because /v1/chat/completions rejects that combination and asks callers to use /v1/responses. The openai/azure auto-bridge already handles this, but responses_api_bridge_check excluded github_copilot, and the copilot responses config gate (github_copilot_supports_responses_api) opts a model out on its default mode=chat, so even a widened gate would bounce the request back to chat and hit the same error Widen the bridge gate to include github_copilot on the gpt-5.4+ tools path, and teach github_copilot_supports_responses_api to treat gpt-5.4+ as responses-capable so the native responses config is selected instead of falling back to chat completions Resolves #23156 Claude-Session: https://claude.ai/code/session_01WYJUHss1GQFdd3uC4J1vyT --- .../responses/transformation.py | 15 +++-- litellm/main.py | 13 ++++- ...github_copilot_responses_transformation.py | 28 +++++++++ tests/test_litellm/test_main.py | 57 +++++++++++++++++++ 4 files changed, 106 insertions(+), 7 deletions(-) diff --git a/litellm/llms/github_copilot/responses/transformation.py b/litellm/llms/github_copilot/responses/transformation.py index 5a4bb798851..c02bfee0d9d 100644 --- a/litellm/llms/github_copilot/responses/transformation.py +++ b/litellm/llms/github_copilot/responses/transformation.py @@ -43,14 +43,21 @@ def github_copilot_supports_responses_api(model: str) -> bool: """ Gate native /v1/responses dispatch per github_copilot model. - Resolution (first match wins): mode "responses" -> True; mode "chat" -> - False (opt-out wins for dual-endpoint models); "/v1/responses" in - supported_endpoints -> True; else False. Unknown model -> False (the bridge - always works since every Copilot model supports /chat/completions). + Resolution (first match wins): gpt-5.4+ -> True (responses-capable even + though the map default mode is "chat", so tools + reasoning_effort can be + bridged); mode "responses" -> True; mode "chat" -> False (opt-out wins for + dual-endpoint models); "/v1/responses" in supported_endpoints -> True; else + False. Unknown model -> False (the bridge always works since every Copilot + model supports /chat/completions). Reads merged model info (per-deployment model_info applied via the router's register_model, which also clears the cache used here). """ + from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config + + if OpenAIGPT5Config.is_model_gpt_5_4_plus_model(model): + return True + try: info: Final = _cached_get_model_info_helper(model=model, custom_llm_provider="github_copilot") except Exception as e: diff --git a/litellm/main.py b/litellm/main.py index 75b7f7f10a5..2830663240d 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1087,17 +1087,24 @@ def responses_api_bridge_check( custom_llm_provider == "azure" or resolved_api_base == "" or _is_openai_backed_api_base(resolved_api_base) ) if ( - custom_llm_provider in ("openai", "azure") + custom_llm_provider in ("openai", "azure", "github_copilot") and model_info.get("mode") != "responses" and OpenAIGPT5Config.is_model_gpt_5_model(model) and not OpenAIGPT5Config.is_model_gpt_5_search_model(model) and ( - (reasoning_effort is not None and reasoning_summary is not None) + ( + reasoning_effort is not None + and reasoning_summary is not None + and custom_llm_provider in ("openai", "azure") + ) or ( OpenAIGPT5Config.is_model_gpt_5_4_plus_model(model) and has_function_tool and reasoning_active - and (reasoning_effort is not None or on_constraint_enforcing_endpoint) + and ( + reasoning_effort is not None + or (custom_llm_provider in ("openai", "azure") and on_constraint_enforcing_endpoint) + ) ) ) ): diff --git a/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py b/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py index 0174465b0cc..bcce790be1e 100644 --- a/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py +++ b/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py @@ -582,6 +582,34 @@ class TestGithubCopilotResponsesAPIRouting: ) assert isinstance(config, GithubCopilotResponsesAPIConfig) + @patch( + "litellm.llms.github_copilot.responses.transformation._cached_get_model_info_helper" + ) + def test_gpt_5_4_returns_config_even_when_mode_is_chat(self, mock_get_info): + """gpt-5.4+ is responses-capable and overrides the ``mode=chat`` opt-out. + + Regression for https://github.com/BerriAI/litellm/issues/23156. The catalog + default for gpt-5.4 is ``mode=chat``, but tools + reasoning_effort must be + bridgeable to /v1/responses; without this the completion() responses bridge + would receive a None config and bounce the request back to /v1/chat/completions.""" + mock_get_info.return_value = {"mode": "chat"} + config = ProviderConfigManager.get_provider_responses_api_config( + model="github_copilot/gpt-5.4", + provider=LlmProviders.GITHUB_COPILOT, + ) + assert isinstance(config, GithubCopilotResponsesAPIConfig) + + def test_gpt_5_4_returns_native_config_without_catalog_entry(self): + """github_copilot/gpt-5.4 has no catalog entry, yet must still resolve to the + native responses config via the name-based gpt-5.4+ capability check so the + bridge can route tools + reasoning_effort. Exercises the real + ``_cached_get_model_info_helper`` plumbing (no mock).""" + config = ProviderConfigManager.get_provider_responses_api_config( + model="github_copilot/gpt-5.4", + provider=LlmProviders.GITHUB_COPILOT, + ) + assert isinstance(config, GithubCopilotResponsesAPIConfig) + class TestGithubCopilotReasoningStreamItemIdNormalization: """GitHub Copilot's native /responses stream tags every reasoning-summary diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py index 038df3656fe..db879fce2ec 100644 --- a/tests/test_litellm/test_main.py +++ b/tests/test_litellm/test_main.py @@ -1330,6 +1330,63 @@ def test_responses_api_bridge_check_gpt_5_tools_without_summary_stays_chat(): assert model_info.get("mode") != "responses" +def test_responses_api_bridge_check_github_copilot_gpt_5_4_tools_plus_reasoning_routes_to_responses(): + """github_copilot/gpt-5.4 with tools + reasoning_effort should route to Responses API. + + Regression test for https://github.com/BerriAI/litellm/issues/23156 - the copilot + variant that /v1/chat/completions rejects with "Function tools with reasoning_effort + are not supported for gpt-5.4 ... Please use /v1/responses instead". + """ + 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="github_copilot/gpt-5.4", + custom_llm_provider="github_copilot", + tools=[{"type": "function", "function": {"name": "get_weather"}}], + reasoning_effort="low", + ) + + assert model == "github_copilot/gpt-5.4" + assert model_info.get("mode") == "responses" + + +def test_responses_api_bridge_check_github_copilot_gpt_5_4_tools_without_reasoning_stays_chat(): + """github_copilot/gpt-5.4 with tools but no reasoning_effort should stay on chat.""" + 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="github_copilot/gpt-5.4", + custom_llm_provider="github_copilot", + tools=[{"type": "function", "function": {"name": "get_weather"}}], + reasoning_effort=None, + ) + + assert model_info.get("mode") != "responses" + + +def test_responses_api_bridge_check_github_copilot_gpt_5_1_reasoning_summary_stays_chat(): + """The reasoning_summary bridge path stays openai/azure-only: a copilot gpt-5.1 + (pre-5.4) request with reasoning_effort + reasoning_summary but no tools must NOT + bridge, so copilot is not lumped into the untested summary path.""" + 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="github_copilot/gpt-5.1", + custom_llm_provider="github_copilot", + tools=None, + reasoning_effort="medium", + reasoning_summary="auto", + ) + + assert model_info.get("mode") != "responses" + + @patch("litellm.completion_extras.responses_api_bridge.completion") def test_gpt_5_4_responses_bridge_preserves_reasoning_summary_dict( mock_responses_completion, From 851c066e1b32f461456addfb1114bc693e812117 Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Mon, 6 Jul 2026 23:50:52 -0400 Subject: [PATCH 2/2] refactor(responses-bridge): move gpt-5 chat->responses decision into OpenAIGPT5Config The provider allow-list and gpt-5 model checks that decide whether a chat/completions request is bridged to the Responses API lived inline in responses_api_bridge_check in litellm/main.py. Extract them into a typed, early-return classmethod OpenAIGPT5Config.is_gpt5_responses_bridge_case so the provider-specific routing logic lives under llms/ rather than in the core request path Behavior is unchanged; the existing openai, azure, and github_copilot bridge tests cover it Claude-Session: https://claude.ai/code/session_01WYJUHss1GQFdd3uC4J1vyT --- .../llms/openai/chat/gpt_5_transformation.py | 31 ++++++++ litellm/main.py | 30 +++----- ...github_copilot_responses_transformation.py | 17 +++-- tests/test_litellm/test_main.py | 75 ++++++++++++------- 4 files changed, 98 insertions(+), 55 deletions(-) diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_5_transformation.py index b02f953425d..31ccab3d282 100644 --- a/litellm/llms/openai/chat/gpt_5_transformation.py +++ b/litellm/llms/openai/chat/gpt_5_transformation.py @@ -127,6 +127,37 @@ class OpenAIGPT5Config(OpenAIGPTConfig): except (ValueError, IndexError): return False + @classmethod + def is_gpt5_responses_bridge_case( + cls, + model: str, + custom_llm_provider: str, + is_responses_mode: bool, + has_function_tool: bool, + has_reasoning_effort: bool, + has_reasoning_summary: bool, + reasoning_active: bool, + on_constraint_enforcing_endpoint: bool, + ) -> bool: + """Whether a GPT-5 chat request needs the Responses API for its tools or reasoning.""" + if custom_llm_provider not in ("openai", "azure", "github_copilot"): + return False + if is_responses_mode: + return False + if not cls.is_model_gpt_5_model(model) or cls.is_model_gpt_5_search_model(model): + return False + if has_reasoning_effort and has_reasoning_summary and custom_llm_provider in ("openai", "azure"): + return True + return ( + cls.is_model_gpt_5_4_plus_model(model) + and has_function_tool + and reasoning_active + and ( + has_reasoning_effort + or (custom_llm_provider in ("openai", "azure") and on_constraint_enforcing_endpoint) + ) + ) + @classmethod def _model_map_lookup_name(cls, model: str) -> str: """The name this model is looked up by in the cost map. diff --git a/litellm/main.py b/litellm/main.py index 2830663240d..d032928a306 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1086,27 +1086,15 @@ def responses_api_bridge_check( on_constraint_enforcing_endpoint: Final = ( custom_llm_provider == "azure" or resolved_api_base == "" or _is_openai_backed_api_base(resolved_api_base) ) - if ( - custom_llm_provider in ("openai", "azure", "github_copilot") - and model_info.get("mode") != "responses" - and OpenAIGPT5Config.is_model_gpt_5_model(model) - and not OpenAIGPT5Config.is_model_gpt_5_search_model(model) - and ( - ( - reasoning_effort is not None - and reasoning_summary is not None - and custom_llm_provider in ("openai", "azure") - ) - or ( - OpenAIGPT5Config.is_model_gpt_5_4_plus_model(model) - and has_function_tool - and reasoning_active - and ( - reasoning_effort is not None - or (custom_llm_provider in ("openai", "azure") and on_constraint_enforcing_endpoint) - ) - ) - ) + if OpenAIGPT5Config.is_gpt5_responses_bridge_case( + model=model, + custom_llm_provider=custom_llm_provider, + is_responses_mode=model_info.get("mode") == "responses", + has_function_tool=has_function_tool, + has_reasoning_effort=reasoning_effort is not None, + has_reasoning_summary=reasoning_summary is not None, + reasoning_active=reasoning_active, + on_constraint_enforcing_endpoint=on_constraint_enforcing_endpoint, ): model_info["mode"] = "responses" model = model.replace("responses/", "") diff --git a/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py b/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py index bcce790be1e..e06c542b16c 100644 --- a/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py +++ b/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py @@ -582,17 +582,24 @@ class TestGithubCopilotResponsesAPIRouting: ) assert isinstance(config, GithubCopilotResponsesAPIConfig) - @patch( - "litellm.llms.github_copilot.responses.transformation._cached_get_model_info_helper" - ) - def test_gpt_5_4_returns_config_even_when_mode_is_chat(self, mock_get_info): + def test_gpt_5_4_returns_config_even_when_mode_is_chat(self) -> None: """gpt-5.4+ is responses-capable and overrides the ``mode=chat`` opt-out. Regression for https://github.com/BerriAI/litellm/issues/23156. The catalog default for gpt-5.4 is ``mode=chat``, but tools + reasoning_effort must be bridgeable to /v1/responses; without this the completion() responses bridge would receive a None config and bounce the request back to /v1/chat/completions.""" - mock_get_info.return_value = {"mode": "chat"} + litellm.register_model( + { + "github_copilot/gpt-5.4": { + "litellm_provider": "github_copilot", + "max_tokens": 128000, + "input_cost_per_token": 0, + "output_cost_per_token": 0, + "mode": "chat", + } + } + ) config = ProviderConfigManager.get_provider_responses_api_config( model="github_copilot/gpt-5.4", provider=LlmProviders.GITHUB_COPILOT, diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py index db879fce2ec..86a08c45355 100644 --- a/tests/test_litellm/test_main.py +++ b/tests/test_litellm/test_main.py @@ -1330,7 +1330,25 @@ def test_responses_api_bridge_check_gpt_5_tools_without_summary_stays_chat(): assert model_info.get("mode") != "responses" -def test_responses_api_bridge_check_github_copilot_gpt_5_4_tools_plus_reasoning_routes_to_responses(): +@pytest.fixture +def github_copilot_chat_catalog(local_model_cost_map: None) -> None: + litellm.register_model( + { + f"github_copilot/{model}": { + "litellm_provider": "github_copilot", + "max_tokens": 128000, + "input_cost_per_token": 0, + "output_cost_per_token": 0, + "mode": "chat", + } + for model in ("gpt-5.4", "gpt-5.1") + } + ) + + +def test_responses_api_bridge_check_github_copilot_gpt_5_4_tools_plus_reasoning_routes_to_responses( + github_copilot_chat_catalog: None, +) -> None: """github_copilot/gpt-5.4 with tools + reasoning_effort should route to Responses API. Regression test for https://github.com/BerriAI/litellm/issues/23156 - the copilot @@ -1339,50 +1357,49 @@ def test_responses_api_bridge_check_github_copilot_gpt_5_4_tools_plus_reasoning_ """ 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="github_copilot/gpt-5.4", - custom_llm_provider="github_copilot", - tools=[{"type": "function", "function": {"name": "get_weather"}}], - reasoning_effort="low", - ) + model_info, model = responses_api_bridge_check( + model="github_copilot/gpt-5.4", + custom_llm_provider="github_copilot", + tools=[{"type": "function", "function": {"name": "get_weather"}}], + reasoning_effort="low", + ) assert model == "github_copilot/gpt-5.4" assert model_info.get("mode") == "responses" -def test_responses_api_bridge_check_github_copilot_gpt_5_4_tools_without_reasoning_stays_chat(): - """github_copilot/gpt-5.4 with tools but no reasoning_effort should stay on chat.""" +@pytest.mark.parametrize("reasoning_effort", [None, "none", {"effort": "none"}]) +def test_responses_api_bridge_check_github_copilot_gpt_5_4_tools_without_reasoning_stays_chat( + reasoning_effort: str | dict[str, str] | None, + github_copilot_chat_catalog: None, +) -> None: 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="github_copilot/gpt-5.4", - custom_llm_provider="github_copilot", - tools=[{"type": "function", "function": {"name": "get_weather"}}], - reasoning_effort=None, - ) + model_info, model = responses_api_bridge_check( + model="github_copilot/gpt-5.4", + custom_llm_provider="github_copilot", + tools=[{"type": "function", "function": {"name": "get_weather"}}], + reasoning_effort=reasoning_effort, + ) assert model_info.get("mode") != "responses" -def test_responses_api_bridge_check_github_copilot_gpt_5_1_reasoning_summary_stays_chat(): +def test_responses_api_bridge_check_github_copilot_gpt_5_1_reasoning_summary_stays_chat( + github_copilot_chat_catalog: None, +) -> None: """The reasoning_summary bridge path stays openai/azure-only: a copilot gpt-5.1 (pre-5.4) request with reasoning_effort + reasoning_summary but no tools must NOT bridge, so copilot is not lumped into the untested summary path.""" 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="github_copilot/gpt-5.1", - custom_llm_provider="github_copilot", - tools=None, - reasoning_effort="medium", - reasoning_summary="auto", - ) + model_info, model = responses_api_bridge_check( + model="github_copilot/gpt-5.1", + custom_llm_provider="github_copilot", + tools=None, + reasoning_effort="medium", + reasoning_summary="auto", + ) assert model_info.get("mode") != "responses"