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
feat: Add xhigh reasoning effort for gpt-5.1-codex-max (#17585)
Sungjun.Kimca7241188a0a
diff --git a/docs/my-website/docs/providers/openai.md b/docs/my-website/docs/providers/openai.mdindex 0babcb50c59..f1f88999d83 100644--- a/docs/my-website/docs/providers/openai.md+++ b/docs/my-website/docs/providers/openai.md@@ -428,7 +428,7 @@ Expected Response:### Advanced: Using `reasoning_effort` with `summary` field-By default, `reasoning_effort` accepts a string value (`"none"`, `"minimal"`, `"low"`, `"medium"`, `"high"`) and only sets the effort level without including a reasoning summary.+By default, `reasoning_effort` accepts a string value (`"none"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`—`"xhigh"` is only supported on `gpt-5.1-codex-max`) and only sets the effort level without including a reasoning summary.To opt-in to the `summary` feature, you can pass `reasoning_effort` as a dictionary. **Note:** The `summary` field requires your OpenAI organization to have verification status. Using `summary` without verification will result in a 400 error from OpenAI.@@ -495,11 +495,12 @@ curl -X POST 'http://0.0.0.0:4000/chat/completions' \| `gpt-5-codex` | `adaptive` | `low`, `medium`, `high` (no `minimal`) || `gpt-5.1-codex` | `adaptive` | `low`, `medium`, `high` (no `minimal`) || `gpt-5.1-codex-mini` | `adaptive` | `low`, `medium`, `high` (no `minimal`) |-| `gpt-5.1-codex-max` | `adaptive` | `low`, `medium`, `high` (no `minimal`) |+| `gpt-5.1-codex-max` | `adaptive` | `low`, `medium`, `high`, `xhigh` (no `minimal`) || `gpt-5-pro` | `high` | `high` only |**Note:**- GPT-5.1 introduced a new `reasoning_effort="none"` setting for faster, lower-latency responses. This replaces the `"minimal"` setting from GPT-5.+- `gpt-5.1-codex-max` is the only model that supports `reasoning_effort="xhigh"`. All other models will reject this value.- `gpt-5-pro` only accepts `reasoning_effort="high"`. Other values will return an error.- When `reasoning_effort` is not set (None), OpenAI defaults to the value shown in the "Default" column.@@ -990,4 +991,4 @@ response = completion(LiteLLM supports OpenAI's video generation models including Sora.-For detailed documentation on video generation, see [OpenAI Video Generation →](./openai/video_generation.md)\ No newline at end of file+For detailed documentation on video generation, see [OpenAI Video Generation →](./openai/video_generation.md)diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.pyindex c4233140b31..93379ba5e00 100644--- a/litellm/completion_extras/litellm_responses_transformation/transformation.py+++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py@@ -632,6 +632,8 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):return Reasoning(effort="none") # type: ignoreelif reasoning_effort == "high":return Reasoning(effort="high")+ elif reasoning_effort == "xhigh":+ return Reasoning(effort="xhigh")elif reasoning_effort == "medium":return Reasoning(effort="medium")elif reasoning_effort == "low":diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_5_transformation.pyindex 60a172ef817..0cbc0192e2a 100644--- a/litellm/llms/openai/chat/gpt_5_transformation.py+++ b/litellm/llms/openai/chat/gpt_5_transformation.py@@ -25,6 +25,12 @@ class OpenAIGPT5Config(OpenAIGPTConfig):def is_model_gpt_5_codex_model(cls, model: str) -> bool:"""Check if the model is specifically a GPT-5 Codex variant."""return "gpt-5-codex" in model++ @classmethod+ def is_model_gpt_5_1_codex_max_model(cls, model: str) -> bool:+ """Check if the model is the gpt-5.1-codex-max variant."""+ model_name = model.split("/")[-1] # handle provider prefixes+ return model_name == "gpt-5.1-codex-max"@classmethoddef is_model_gpt_5_1_model(cls, model: str) -> bool:@@ -66,6 +72,22 @@ class OpenAIGPT5Config(OpenAIGPTConfig):model: str,drop_params: bool,) -> dict:+ reasoning_effort = (+ non_default_params.get("reasoning_effort")+ or optional_params.get("reasoning_effort")+ )+ if reasoning_effort is not None and reasoning_effort == "xhigh":+ if not self.is_model_gpt_5_1_codex_max_model(model):+ if litellm.drop_params or drop_params:+ pass+ else:+ raise litellm.utils.UnsupportedParamsError(+ message=(+ "reasoning_effort='xhigh' is only supported for gpt-5.1-codex-max."+ ),+ status_code=400,+ )+################################################################# max_tokens is not supported for gpt-5 models on OpenAI API# Relevant issue: https://github.com/BerriAI/litellm/issues/13381@@ -79,10 +101,6 @@ class OpenAIGPT5Config(OpenAIGPTConfig):temperature_value: Optional[float] = non_default_params.pop("temperature")if temperature_value is not None:is_gpt_5_1 = self.is_model_gpt_5_1_model(model)- reasoning_effort = (- non_default_params.get("reasoning_effort")- or optional_params.get("reasoning_effort")- )# gpt-5.1 supports any temperature when reasoning_effort="none" (or not specified, as it defaults to "none")if is_gpt_5_1 and (reasoning_effort == "none" or reasoning_effort is None):diff --git a/litellm/main.py b/litellm/main.pyindex 3eaa4527f8b..67b1800e152 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -390,7 +390,7 @@ async def acompletion(top_logprobs: Optional[int] = None,deployment_id=None,reasoning_effort: Optional[- Literal["none", "minimal", "low", "medium", "high", "default"]+ Literal["none", "minimal", "low", "medium", "high", "xhigh", "default"]] = None,verbosity: Optional[Literal["low", "medium", "high"]] = None,safety_identifier: Optional[str] = None,@@ -1003,7 +1003,7 @@ def completion( # type: ignore # noqa: PLR0915user: Optional[str] = None,# openai v1.0+ new paramsreasoning_effort: Optional[- Literal["none", "minimal", "low", "medium", "high", "default"]+ Literal["none", "minimal", "low", "medium", "high", "xhigh", "default"]] = None,verbosity: Optional[Literal["low", "medium", "high"]] = None,response_format: Optional[Union[dict, Type[BaseModel]]] = None,diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex 377ba546988..59397a62a8b 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -1488,7 +1488,7 @@ ResponsesAPIStreamingResponse = Annotated[]-REASONING_EFFORT = Literal["none", "minimal", "low", "medium", "high"]+REASONING_EFFORT = Literal["none", "minimal", "low", "medium", "high", "xhigh"]class OpenAIRealtimeStreamSession(TypedDict, total=False):diff --git a/tests/test_litellm/llms/openai/test_gpt5_transformation.py b/tests/test_litellm/llms/openai/test_gpt5_transformation.pyindex 98d4ba9c10f..8b2c7fa27eb 100644--- a/tests/test_litellm/llms/openai/test_gpt5_transformation.py+++ b/tests/test_litellm/llms/openai/test_gpt5_transformation.py@@ -211,6 +211,36 @@ def test_gpt5_1_reasoning_effort_none(config: OpenAIConfig):assert params["reasoning_effort"] == effort+def test_gpt5_1_codex_max_allows_reasoning_effort_xhigh(config: OpenAIConfig):+ params = config.map_openai_params(+ non_default_params={"reasoning_effort": "xhigh"},+ optional_params={},+ model="gpt-5.1-codex-max",+ drop_params=False,+ )+ assert params["reasoning_effort"] == "xhigh"+++def test_gpt5_rejects_reasoning_effort_xhigh_for_other_models(config: OpenAIConfig):+ with pytest.raises(litellm.utils.UnsupportedParamsError):+ config.map_openai_params(+ non_default_params={"reasoning_effort": "xhigh"},+ optional_params={},+ model="gpt-5.1",+ drop_params=False,+ )+++def test_gpt5_drops_reasoning_effort_xhigh_when_requested(config: OpenAIConfig):+ params = config.map_openai_params(+ non_default_params={"reasoning_effort": "xhigh"},+ optional_params={},+ model="gpt-5",+ drop_params=True,+ )+ assert "reasoning_effort" not in params++# GPT-5.1 temperature handling testsdef test_gpt5_1_model_detection(gpt5_config: OpenAIGPT5Config):"""Test that GPT-5.1 models are correctly detected."""