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/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 17edafcdfca..c13ab41033e 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1122,20 +1122,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") - 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) - 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) - ) - ) + 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 0174465b0cc..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,6 +582,41 @@ class TestGithubCopilotResponsesAPIRouting: ) assert isinstance(config, GithubCopilotResponsesAPIConfig) + 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.""" + 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, + ) + 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 4f7a51eb531..e90b4f7ce80 100644 --- a/tests/test_litellm/test_main.py +++ b/tests/test_litellm/test_main.py @@ -1340,6 +1340,80 @@ def test_responses_api_bridge_check_gpt_5_tools_without_summary_stays_chat(): assert model_info.get("mode") != "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 + 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 + + 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" + + +@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 + + 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( + 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 + + 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,