Skip to content

fix(responses-api): apply GPT-5 temperature validation - #24371

Merged
Chesars merged 3 commits into
BerriAI:litellm_staging_03_22_2026from
Chesars:fix/responses-api-gpt5-temperature-drop-params
Mar 22, 2026
Merged

fix(responses-api): apply GPT-5 temperature validation#24371
Chesars merged 3 commits into
BerriAI:litellm_staging_03_22_2026from
Chesars:fix/responses-api-gpt5-temperature-drop-params

Conversation

@Chesars

@Chesars Chesars commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #16090

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

Changes

The Responses API map_openai_params passed all params through without model-specific validation. GPT-5 models (except gpt-5-chat) only accept temperature=1 unless reasoning.effort="none" on models that support it (5.1, 5.2, 5.4). The chat completions path already validates this, but the Responses API path did not.

Tests added

  • test_responses_gpt5_drop_temperature — drop_params drops temperature!=1
  • test_responses_gpt5_reject_temperature — raises error without drop_params
  • test_responses_gpt5_allow_temperature_1 — temperature=1 always allowed
  • test_responses_gpt5_mini_drop_temperature — gpt-5-mini also drops
  • test_responses_gpt5_chat_allow_temperature — gpt-5-chat not restricted

The Responses API map_openai_params passed all params through without
applying model-specific validation. GPT-5 models (except gpt-5-chat)
only accept temperature=1 unless reasoning.effort="none" on models
that support it (5.1, 5.2, 5.4).

Reuse the existing OpenAIGPT5Config logic from chat completions to
validate temperature in the Responses API path. With drop_params=True,
unsupported temperature values are silently dropped; without it,
UnsupportedParamsError is raised.

Fixes BerriAI#16090
@vercel

vercel Bot commented Mar 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 22, 2026 9:39pm

Request Review

@codspeed-hq

codspeed-hq Bot commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing Chesars:fix/responses-api-gpt5-temperature-drop-params (bfee7f0) with main (c89496f)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds GPT-5 temperature validation to the Responses API map_openai_params path, fixing a gap where the chat completions path already enforced that GPT-5 models (except gpt-5-chat) only accept temperature=1 — unless reasoning.effort='none' on models like gpt-5.1/5.4 that support it — but the Responses API path passed all parameters through without any validation.

Changes:

  • litellm/llms/openai/responses/transformation.py: map_openai_params now reuses OpenAIGPT5Config.is_model_gpt_5_model and _supports_reasoning_effort_level to apply the same temperature guard that exists in the chat completions path; raises UnsupportedParamsError or drops the param according to drop_params.
  • tests/test_litellm/llms/openai/test_gpt5_transformation.py: 7 new pure unit tests covering drop, reject, allow (temperature=1), gpt-5-mini, gpt-5-chat bypass, gpt-5.1 no-effort, and gpt-5.1/5.4 with explicit effort values.

Notes:

  • The fix correctly mirrors the existing chat completions logic, including the effort is None → allows temperature semantic for supports-none models.
  • is_model_gpt_5_model relies on a hardcoded substring check rather than the model map (model_prices_and_context_window.json), which is an existing pattern but now applied to the Responses API path as well. A future follow-up using _supports_factory for temperature restriction detection would be more future-proof and consistent with the project's custom rule.
  • This change is technically a behavior shift: callers previously received an API-level HTTP 400; they now receive litellm.UnsupportedParamsError before the network call is made. Existing code catching openai.BadRequestError should be updated to also handle litellm.UnsupportedParamsError.

Confidence Score: 4/5

  • Safe to merge — the fix is correct, well-tested, and consistent with the existing chat completions path; only minor style/future-proofing concerns remain.
  • The core logic faithfully mirrors the established chat completions path, unit test coverage is thorough (no network calls, multiple model variants), and the error path is validated. The score is not 5 because the hardcoded model-detection helper (is_model_gpt_5_model) deviates from the project's preferred model-map-driven pattern, and the exception-type change (litellm-layer error vs. API-layer error) could silently break existing callers' exception handling.
  • No files require special attention; litellm/llms/openai/responses/transformation.py is the only logic change and it is straightforward.

Important Files Changed

Filename Overview
litellm/llms/openai/responses/transformation.py Adds GPT-5 temperature validation to map_openai_params, mirroring the chat completions path. Logic is correct and consistent; minor concern around hardcoded model detection (reusing existing helper) and a behavior-level change in exception type (UnsupportedParamsError raised earlier instead of API-level 400).
tests/test_litellm/llms/openai/test_gpt5_transformation.py Adds 7 new unit tests covering drop, reject, and allow paths for several model variants. All tests are pure in-memory (no network calls), satisfying the test-folder constraint. Missing a reject-path test for supports-none models (e.g. gpt-5.1 + effort='high' + drop_params=False), but this was noted in previous review threads.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[map_openai_params called] --> B{is_model_gpt_5_model?}
    B -- No --> Z[return params as-is]
    B -- Yes --> C{temperature in params\nAND temperature != 1?}
    C -- No --> Z
    C -- Yes --> D[extract reasoning.effort]
    D --> E{_supports_reasoning_effort_level\nlevel='none'?}
    E -- Yes, supports_none=True --> F{effort == 'none'\nOR effort is None?}
    F -- Yes --> Z[return params with temperature]
    F -- No --> G{drop_params\nOR litellm.drop_params?}
    E -- No, supports_none=False --> G
    G -- Yes --> H[pop temperature from params]
    H --> Z
    G -- No --> I[raise UnsupportedParamsError 400]
Loading

Reviews (3): Last reviewed commit: "fix: improve error message for supports-..." | Re-trigger Greptile

Comment thread litellm/llms/openai/responses/transformation.py
Comment thread litellm/llms/openai/responses/transformation.py
…rature

Add tests for the gpt-5.1/5.2/5.4 reasoning.effort interaction:
- gpt-5.1 with no reasoning allows flexible temperature
- gpt-5.1 with effort='high' drops temperature
- gpt-5.4 with effort='none' allows flexible temperature
Comment thread litellm/llms/openai/responses/transformation.py
Comment thread tests/test_litellm/llms/openai/test_gpt5_transformation.py
@Chesars
Chesars changed the base branch from main to litellm_staging_03_22_2026 March 22, 2026 21:42
Comment thread litellm/llms/openai/responses/transformation.py
Comment thread litellm/llms/openai/responses/transformation.py
@Chesars
Chesars merged commit 16c48b4 into BerriAI:litellm_staging_03_22_2026 Mar 22, 2026
37 of 39 checks passed
@Chesars
Chesars deleted the fix/responses-api-gpt5-temperature-drop-params branch March 22, 2026 21:44
Chesars added a commit that referenced this pull request Apr 16, 2026
- factory.py: fix _sort_bedrock_assistant_content_blocks to treat
  cachePoint blocks with the same sort key as toolUse so Python's
  stable sort keeps each cachePoint paired with its preceding toolUse
  block (PR #24368)

- responses/transformation.py: remove cyclic import of OpenAIGPT5Config
  inside map_openai_params; add _is_gpt_5_model and
  _supports_reasoning_effort_none static methods that replicate the
  same logic without the import cycle. _is_gpt_5_model now also
  excludes pass-through models from other providers (e.g.
  perplexity/openai/gpt-5.2) that contain 'gpt-5' in their name but
  should not be subject to OpenAI GPT-5 temperature restrictions
  (PR #24371)
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…temperature-drop-params

fix(responses-api): apply GPT-5 temperature validation
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
- factory.py: fix _sort_bedrock_assistant_content_blocks to treat
  cachePoint blocks with the same sort key as toolUse so Python's
  stable sort keeps each cachePoint paired with its preceding toolUse
  block (PR BerriAI#24368)

- responses/transformation.py: remove cyclic import of OpenAIGPT5Config
  inside map_openai_params; add _is_gpt_5_model and
  _supports_reasoning_effort_none static methods that replicate the
  same logic without the import cycle. _is_gpt_5_model now also
  excludes pass-through models from other providers (e.g.
  perplexity/openai/gpt-5.2) that contain 'gpt-5' in their name but
  should not be subject to OpenAI GPT-5 temperature restrictions
  (PR BerriAI#24371)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LiteLLM Proxy doesn't drop temperature parameter for gpt-5 models when drop_params is enabled

1 participant