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 GPT-5 reasoning summary alias stripping
Cursor Agent0ac923c6b633
diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_5_transformation.pyindex a665ef65e5a..9ccb2e1c267 100644--- a/litellm/llms/openai/chat/gpt_5_transformation.py+++ b/litellm/llms/openai/chat/gpt_5_transformation.py@@ -6,7 +6,6 @@ import litellmfrom litellm.utils import (_is_explicitly_disabled_factory,_supports_factory,- strip_reasoning_summary_aliases_from_openai_completion_params,)from .gpt_transformation import OpenAIGPTConfig@@ -195,16 +194,6 @@ class OpenAIGPT5Config(OpenAIGPTConfig):if param not in non_supported_params]- @staticmethod- def _strip_reasoning_summary_aliases_for_chat_completions(- non_default_params: dict,- optional_params: dict,- ) -> None:- """Remove Responses-style reasoning summary keys; invalid on Chat Completions."""- strip_reasoning_summary_aliases_from_openai_completion_params(- non_default_params, optional_params- )-def map_openai_params(self,non_default_params: dict,@@ -212,12 +201,6 @@ class OpenAIGPT5Config(OpenAIGPTConfig):model: str,drop_params: bool,) -> dict:- # AI SDK / Responses-style aliases; never valid on Chat Completions when not- # bridged to Responses API (see main.responses_api_bridge_check).- self._strip_reasoning_summary_aliases_for_chat_completions(- non_default_params, optional_params- )-if self.is_model_gpt_5_search_model(model):if "max_tokens" in non_default_params:optional_params["max_completion_tokens"] = non_default_params.pop(diff --git a/litellm/main.py b/litellm/main.pyindex 6a3e5db2057..94915503803 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -1696,6 +1696,16 @@ def completion( # type: ignore # noqa: PLR0915encoding=_get_encoding(),stream=stream,)+ elif (+ custom_llm_provider == "openai"+ and OpenAIGPT5Config.is_model_gpt_5_model(model)+ ) or (+ custom_llm_provider == "azure"+ and litellm.AzureOpenAIGPT5Config.is_model_gpt_5_model(model)+ ):+ optional_params, _ = strip_reasoning_summary_aliases_from_optional_params(+ optional_params+ )if custom_llm_provider == "azure":# azure configsdiff --git a/litellm/utils.py b/litellm/utils.pyindex f61a47c4011..daac5234003 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -9533,22 +9533,6 @@ def strip_reasoning_summary_aliases_from_optional_params(return op, rs_val-def strip_reasoning_summary_aliases_from_openai_completion_params(- non_default_params: dict,- optional_params: dict,-) -> None:- """Drop AI-SDK reasoning summary keys from chat completion param dicts (in-place).-- These aliases are not valid on OpenAI Chat Completions and may appear on- ``non_default_params`` or ``optional_params`` (including nested ``extra_body``).- """- non_default_params.pop("reasoningSummary", None)- non_default_params.pop("reasoning_summary", None)- stripped, _ = strip_reasoning_summary_aliases_from_optional_params(optional_params)- optional_params.clear()- optional_params.update(stripped)--def get_non_default_transcription_params(kwargs: dict) -> dict:from litellm.constants import OPENAI_TRANSCRIPTION_PARAMSdiff --git a/tests/test_litellm/llms/openai/test_gpt5_transformation.py b/tests/test_litellm/llms/openai/test_gpt5_transformation.pyindex be079ee7086..840f2c75fde 100644--- a/tests/test_litellm/llms/openai/test_gpt5_transformation.py+++ b/tests/test_litellm/llms/openai/test_gpt5_transformation.py@@ -1,6 +1,7 @@import pytestimport litellm+import litellm.main as litellm_mainfrom litellm.litellm_core_utils.get_model_cost_map import get_model_cost_mapfrom litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Configfrom litellm.llms.openai.openai import OpenAIConfig@@ -1011,32 +1012,35 @@ def test_gpt5_search_drops_unsupported_params(config: OpenAIConfig):assert "tools" not in params-def test_gpt5_search_strips_reasoning_summary_aliases(gpt5_config: OpenAIGPT5Config):- """Search models still strip Responses-only reasoning summary aliases."""- non_default_params = {- "reasoningSummary": "auto",- "reasoning_summary": "ignored",- }- optional_params = {- "extra_body": {- "reasoningSummary": "auto",- "reasoning_summary": "ignored",- "metadata": "ok",- }- }+def test_gpt5_chat_strips_reasoning_summary_aliases_after_bridge_check(+ monkeypatch: pytest.MonkeyPatch,+):+ """Non-bridged GPT-5 chat calls strip Responses-only reasoning summary aliases."""+ captured_kwargs = {}- params = gpt5_config.map_openai_params(- non_default_params=non_default_params,- optional_params=optional_params,- model="gpt-5-search-api",- drop_params=False,+ def fake_openai_completion(**kwargs):+ captured_kwargs.update(kwargs)+ return {}++ monkeypatch.setattr(+ litellm_main.openai_chat_completions,+ "completion",+ fake_openai_completion,+ )++ litellm.completion(+ model="gpt-5",+ messages=[{"role": "user", "content": "ok"}],+ reasoning_effort="medium",+ reasoningSummary="auto",+ extra_body={"reasoning_summary": "ignored", "metadata": "ok"},+ api_key="fake-key",)- assert "reasoningSummary" not in non_default_params- assert "reasoning_summary" not in non_default_params- assert "reasoningSummary" not in params- assert "reasoning_summary" not in params- assert params["extra_body"] == {"metadata": "ok"}+ optional_params = captured_kwargs["optional_params"]+ assert "reasoningSummary" not in optional_params+ assert "reasoning_summary" not in optional_params+ assert optional_params["extra_body"] == {"metadata": "ok"}def test_reasoning_summary_alias_helpers_preserve_falsy_and_strip_all_aliases():