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(responses): drop top_p for gpt-5 reasoning models when drop_params is set
Devin AI4f585d393147
diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.pyindex 833ae206024..0d8d6934795 100644--- a/litellm/llms/openai/responses/transformation.py+++ b/litellm/llms/openai/responses/transformation.py@@ -208,8 +208,9 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):) -> dict:"""No mapping applied since inputs are in OpenAI spec already.- GPT-5 models have restrictions on temperature (only temperature=1- is accepted unless reasoning_effort='none' on models that support it).+ GPT-5 models have restrictions on temperature and top_p (only temperature=1+ is accepted, and top_p is rejected, unless reasoning.effort resolves to+ 'none' on models that support it).Apply the same validation used by the chat completions path."""params: Final = dict(response_api_optional_params)@@ -235,12 +236,14 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):)if self._is_gpt_5_model(model=model):+ reasoning: Final = params.get("reasoning") or {}+ effort: Final = reasoning.get("effort") if isinstance(reasoning, dict) else None+ supports_none: Final = self._supports_reasoning_effort_none(model=model)+ effort_is_none: Final = supports_none and self._effort_resolves_to_none(model, effort)+temperature: Final = params.get("temperature")if temperature is not None and temperature != 1:- reasoning: Final = params.get("reasoning") or {}- effort: Final = reasoning.get("effort") if isinstance(reasoning, dict) else None- supports_none: Final = self._supports_reasoning_effort_none(model=model)- if supports_none and self._effort_resolves_to_none(model, effort):+ if effort_is_none:pass # flexible temperature allowedelif drop_params or litellm.drop_params:params.pop("temperature", None)@@ -256,6 +259,20 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):status_code=400,)+ if "top_p" in params and not effort_is_none:+ if drop_params or litellm.drop_params:+ params.pop("top_p", None)+ else:+ raise litellm.UnsupportedParamsError(+ message=(+ f"{model} only supports top_p when reasoning.effort resolves to 'none', "+ "either set explicitly on the request or declared as the model's "+ "default_reasoning_effort. "+ "To drop unsupported params set `litellm.drop_params = True`"+ ),+ status_code=400,+ )+return paramsdef transform_responses_api_request(diff --git a/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_responses_transformation.py b/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_responses_transformation.pyindex a7aefa714aa..afd284d31c8 100644--- a/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_responses_transformation.py+++ b/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_responses_transformation.py@@ -369,6 +369,29 @@ class TestBedrockMantleResponsesTools:assert "file_search" in str(mock_warning.call_args)+class TestBedrockMantleSamplingParams:+ """Mantle rejects top_p on its gpt-5 reasoning models and non-default temperature+ while reasoning is active, the same rule the OpenAI Responses surface applies, so+ drop_params must strip both before the request leaves."""++ @pytest.mark.parametrize(+ "model",+ [+ "openai.gpt-5.4",+ "openai.gpt-5.5",+ "openai.gpt-5.6-luna",+ ],+ )+ def test_map_openai_params_drops_top_p_and_temperature(self, local_cost_map, model):+ params = BedrockMantleResponsesAPIConfig().map_openai_params(+ response_api_optional_params={"top_p": 0.9, "temperature": 0.2},+ model=model,+ drop_params=True,+ )+ assert "top_p" not in params+ assert "temperature" not in params++class TestBedrockMantleResponsesWebSearch:"""Web Search on Amazon Bedrock is a server-side built-in tool that Mantle runsitself when the caller passes {"type": "web_search"} on the Responses path, sodiff --git a/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py b/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.pyindex 4cf8767764b..2bc8d74e82c 100644--- a/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py+++ b/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py@@ -1835,6 +1835,46 @@ class TestResponsesSurfaceSharesTheEffortRule:)assert ("temperature" in mapped) is temperature_survives+ @pytest.mark.parametrize(+ "model, effort, top_p_survives",+ [+ ("gpt-5.1", None, True),+ ("gpt-5.4", None, True),+ ("gpt-5.5", None, False),+ ("gpt-5.6-terra", None, False),+ ("gpt-5.6-sol", None, False),+ ("gpt-5.6-terra", "none", True),+ ("gpt-5.6-terra", "medium", False),+ ("gpt-6-astra", None, False),+ ("gpt-6-astra", "low", False),+ ],+ )+ def test_top_p_follows_the_resolved_effort(self, local_model_cost_map, model, effort, top_p_survives):+ params = {"top_p": 0.9}+ if effort is not None:+ params["reasoning"] = {"effort": effort}+ mapped = OpenAIResponsesAPIConfig().map_openai_params(+ response_api_optional_params=params,+ model=model,+ drop_params=True,+ )+ assert ("top_p" in mapped) is top_p_survives++ def test_top_p_raises_without_drop_params(self, local_model_cost_map):+ with pytest.raises(litellm.UnsupportedParamsError):+ OpenAIResponsesAPIConfig().map_openai_params(+ response_api_optional_params={"top_p": 0.9},+ model="gpt-5.5",+ drop_params=False,+ )++ mapped = OpenAIResponsesAPIConfig().map_openai_params(+ response_api_optional_params={"top_p": 0.9, "reasoning": {"effort": "none"}},+ model="gpt-5.6-terra",+ drop_params=False,+ )+ assert mapped["top_p"] == 0.9+class TestFlattenToolSchemaCombinatorsWiring:"""Regression tests for MCP tools with a top-level anyOf schema (Codex Desktop).