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(azure): add logprobs support for Azure OpenAI GPT-5.2 model (#18856)
Andrés9768eca33e12
diff --git a/litellm/llms/azure/chat/gpt_5_transformation.py b/litellm/llms/azure/chat/gpt_5_transformation.pyindex 87f81d117f0..506b7fdfe5e 100644--- a/litellm/llms/azure/chat/gpt_5_transformation.py+++ b/litellm/llms/azure/chat/gpt_5_transformation.py@@ -25,7 +25,24 @@ class AzureOpenAIGPT5Config(AzureOpenAIConfig, OpenAIGPT5Config):return "gpt-5" in model or "gpt5_series" in modeldef get_supported_openai_params(self, model: str) -> List[str]:- return OpenAIGPT5Config.get_supported_openai_params(self, model=model)+ """Get supported parameters for Azure OpenAI GPT-5 models.++ Azure OpenAI GPT-5.2 models support logprobs, unlike OpenAI's GPT-5.+ This overrides the parent class to add logprobs support back for gpt-5.2.++ Reference:+ - Tested with Azure OpenAI GPT-5.2 (api-version: 2025-01-01-preview)+ - Azure returns logprobs successfully despite Microsoft's general+ documentation stating reasoning models don't support it.+ """+ params = OpenAIGPT5Config.get_supported_openai_params(self, model=model)++ # Only gpt-5.2 has been verified to support logprobs on Azure+ if self.is_model_gpt_5_2_model(model):+ azure_supported_params = ["logprobs", "top_logprobs"]+ params.extend(azure_supported_params)++ return paramsdef map_openai_params(self,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 91d664c3216..199a16d8590 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@@ -204,3 +204,62 @@ def test_azure_gpt5_reasoning_effort_none_dropped(config: AzureOpenAIGPT5Config))assert "reasoning_effort" not in params or params.get("reasoning_effort") != "none"++# Logprobs support tests for Azure GPT-5.2+def test_azure_gpt5_2_supports_logprobs(config: AzureOpenAIGPT5Config):+ """Test that Azure GPT-5.2 models support logprobs parameters.++ Only Azure OpenAI GPT-5.2 supports logprobs, unlike OpenAI's GPT-5 or Azure's gpt-5/gpt-5.1.+ Tested with gpt-5.2 on api-version 2025-01-01-preview.+ """+ supported_params = config.get_supported_openai_params(model="gpt-5.2")+ assert "logprobs" in supported_params+ assert "top_logprobs" in supported_params+++def test_azure_gpt5_2_with_prefix_supports_logprobs(config: AzureOpenAIGPT5Config):+ """Test that Azure GPT-5.2 with azure/ prefix supports logprobs parameters."""+ supported_params = config.get_supported_openai_params(model="azure/gpt-5.2")+ assert "logprobs" in supported_params+ assert "top_logprobs" in supported_params+++def test_azure_gpt5_2_series_supports_logprobs(config: AzureOpenAIGPT5Config):+ """Test that Azure GPT-5.2 with gpt5_series prefix supports logprobs."""+ supported_params = config.get_supported_openai_params(model="gpt5_series/gpt-5.2")+ assert "logprobs" in supported_params+ assert "top_logprobs" in supported_params+++def test_azure_gpt5_2_logprobs_params_passed_through(config: AzureOpenAIGPT5Config):+ """Test that logprobs parameters are correctly passed through to the API for gpt-5.2."""+ params = config.map_openai_params(+ non_default_params={"logprobs": True, "top_logprobs": 5},+ optional_params={},+ model="azure/gpt-5.2",+ drop_params=False,+ api_version="2025-01-01-preview",+ )+ assert params["logprobs"] is True+ assert params["top_logprobs"] == 5+++def test_azure_gpt5_base_does_not_support_logprobs(config: AzureOpenAIGPT5Config):+ """Test that Azure GPT-5 (non-5.2) does not support logprobs parameters.++ Only gpt-5.2 has been verified to support logprobs on Azure.+ """+ supported_params = config.get_supported_openai_params(model="gpt-5")+ assert "logprobs" not in supported_params+ assert "top_logprobs" not in supported_params+++def test_azure_gpt5_1_does_not_support_logprobs(config: AzureOpenAIGPT5Config):+ """Test that Azure GPT-5.1 does not support logprobs parameters.++ Only gpt-5.2 has been verified to support logprobs on Azure.+ """+ supported_params = config.get_supported_openai_params(model="gpt-5.1")+ assert "logprobs" not in supported_params+ assert "top_logprobs" not in supported_params+