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: allow tool_choice for Azure GPT-5 chat models (#19813)
Jay Prajapati6a9d41234f05
diff --git a/litellm/llms/azure/chat/gpt_5_transformation.py b/litellm/llms/azure/chat/gpt_5_transformation.pyindex 506b7fdfe5e..eeb55911ecf 100644--- a/litellm/llms/azure/chat/gpt_5_transformation.py+++ b/litellm/llms/azure/chat/gpt_5_transformation.py@@ -22,7 +22,8 @@ class AzureOpenAIGPT5Config(AzureOpenAIConfig, OpenAIGPT5Config):Accepts both explicit gpt-5 model names and the ``gpt5_series/`` prefixused for manual routing."""- return "gpt-5" in model or "gpt5_series" in model+ # gpt-5-chat* is a chat model and shouldn't go through GPT-5 reasoning restrictions.+ return ("gpt-5" in model and "gpt-5-chat" not in model) or "gpt5_series" in modeldef get_supported_openai_params(self, model: str) -> List[str]:"""Get supported parameters for Azure OpenAI GPT-5 models.@@ -37,6 +38,11 @@ class AzureOpenAIGPT5Config(AzureOpenAIConfig, OpenAIGPT5Config):"""params = OpenAIGPT5Config.get_supported_openai_params(self, model=model)+ # Azure supports tool_choice for GPT-5 deployments, but the base GPT-5 config+ # can drop it when the deployment name isn't in the OpenAI model registry.+ if "tool_choice" not in params:+ params.append("tool_choice")+# Only gpt-5.2 has been verified to support logprobs on Azureif self.is_model_gpt_5_2_model(model):azure_supported_params = ["logprobs", "top_logprobs"]diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_5_transformation.pyindex 3fffa335fdc..05c003c8b7a 100644--- a/litellm/llms/openai/chat/gpt_5_transformation.py+++ b/litellm/llms/openai/chat/gpt_5_transformation.py@@ -19,7 +19,9 @@ class OpenAIGPT5Config(OpenAIGPTConfig):@classmethoddef is_model_gpt_5_model(cls, model: str) -> bool:- return "gpt-5" in model+ # gpt-5-chat* behaves like a regular chat model (supports temperature, etc.)+ # Don't route it through GPT-5 reasoning-specific parameter restrictions.+ return "gpt-5" in model and "gpt-5-chat" not in model@classmethoddef is_model_gpt_5_codex_model(cls, model: str) -> bool:diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex 4ac4159558f..f5c680990c1 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -3130,7 +3130,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_system_messages": true,- "supports_tool_choice": false,+ "supports_tool_choice": true,"supports_vision": true},"azure/gpt-5-chat-latest": {@@ -3162,7 +3162,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_system_messages": true,- "supports_tool_choice": false,+ "supports_tool_choice": true,"supports_vision": true},"azure/gpt-5-codex": {diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex 4ac4159558f..f5c680990c1 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -3130,7 +3130,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_system_messages": true,- "supports_tool_choice": false,+ "supports_tool_choice": true,"supports_vision": true},"azure/gpt-5-chat-latest": {@@ -3162,7 +3162,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_system_messages": true,- "supports_tool_choice": false,+ "supports_tool_choice": true,"supports_vision": true},"azure/gpt-5-codex": {diff --git a/tests/test_litellm/llms/azure/chat/test_azure_gpt5_transformation.py b/tests/test_litellm/llms/azure/chat/test_azure_gpt5_transformation.pyindex 199a16d8590..25f3d1364f6 100644--- a/tests/test_litellm/llms/azure/chat/test_azure_gpt5_transformation.py+++ b/tests/test_litellm/llms/azure/chat/test_azure_gpt5_transformation.py@@ -16,6 +16,17 @@ def test_azure_gpt5_supports_reasoning_effort(config: AzureOpenAIGPT5Config):)+def test_azure_gpt5_allows_tool_choice_for_deployment_names():+ supported_params = litellm.get_supported_openai_params(+ model="gpt-5-chat-2025-08-07", custom_llm_provider="azure"+ )+ assert supported_params is not None+ assert "tool_choice" in supported_params+ # gpt-5-chat* should not be treated as a GPT-5 reasoning model+ assert "reasoning_effort" not in supported_params+ assert "temperature" in supported_params++def test_azure_gpt5_maps_max_tokens(config: AzureOpenAIGPT5Config):params = config.map_openai_params(non_default_params={"max_tokens": 5},diff --git a/tests/test_litellm/llms/openai/test_gpt5_transformation.py b/tests/test_litellm/llms/openai/test_gpt5_transformation.pyindex fd25d302d07..386f264a4dd 100644--- a/tests/test_litellm/llms/openai/test_gpt5_transformation.py+++ b/tests/test_litellm/llms/openai/test_gpt5_transformation.py@@ -20,6 +20,23 @@ def test_gpt5_supports_reasoning_effort(config: OpenAIConfig):assert "reasoning_effort" in config.get_supported_openai_params(model="gpt-5-mini")+def test_gpt5_chat_does_not_support_reasoning_effort(config: OpenAIConfig):+ assert (+ "reasoning_effort"+ not in config.get_supported_openai_params(model="gpt-5-chat-latest")+ )+++def test_gpt5_chat_supports_temperature(config: OpenAIConfig):+ params = config.map_openai_params(+ non_default_params={"temperature": 0.3},+ optional_params={},+ model="gpt-5-chat-latest",+ drop_params=False,+ )+ assert params["temperature"] == 0.3++def test_gpt5_maps_max_tokens(config: OpenAIConfig):params = config.map_openai_params(non_default_params={"max_tokens": 10},