fix(anthropic_messages): gate sampling params on /v1/messages like /chat/completions - #35057
Closed
mihidumh wants to merge 1 commit into
Closed
Conversation
Contributor
Greptile SummaryThis PR aligns Anthropic
Confidence Score: 5/5The PR appears safe to merge, with the new messages-path behavior matching the established chat-path sampling rules. The changed path delegates capability decisions and global or per-request drop behavior to the existing Anthropic helper, while preserving supported parameters and the allowed temperature value.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/messages/utils.py | Reuses the existing Anthropic sampling-capability helper to filter or reject unsupported parameters without introducing a concrete regression. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_request_optional_param_utils.py | Adds focused unit coverage for dropping, preserving, and rejecting sampling parameters across relevant model forms. |
Reviews (1): Last reviewed commit: "fix(anthropic_messages): gate sampling p..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
mihidumh
force-pushed
the
fix/anthropic-messages-sampling-params
branch
from
August 20, 2026 05:50
8ef7709 to
06e4dcb
Compare
…hat/completions /v1/messages forwarded temperature/top_p/top_k raw to models that removed sampling params (supports_sampling_params: false — Claude 4.7+/Fable 5), producing provider 400s that router fallbacks mask as silent model downgrades. The chat path already gates these via AnthropicModelInfo._apply_sampling_param; reuse it in get_requested_anthropic_messages_optional_param so both endpoints agree: drop under drop_params, else raise the clean client-side 400. Fixes BerriAI#35053
mihidumh
force-pushed
the
fix/anthropic-messages-sampling-params
branch
from
August 20, 2026 07:05
06e4dcb to
9653f58
Compare
5 tasks
Contributor
Author
|
Closing — superseded by #37868, which merged this branch's commit (authorship preserved) into |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
/v1/messagesforwardstemperature/top_p/top_kraw to models that removed them/chat/completionsalready drops the same params for the same modelsHow it solves it:
AnthropicModelInfo._apply_sampling_paramgating in the/v1/messagesparam builderdrop_params(matching/chat/completions), else clean client-side 400temperature=1stays allowed everywhere)Relevant issues
Fixes #35053
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
Screenshots / Proof of Fix
Real Vertex AI call (project-billed, no mocks), identical script before/after this change —
litellm.anthropic_interface.acreatewithmodel="vertex_ai/claude-sonnet-5",temperature=0.3, top_p=0.9, top_k=40,litellm.drop_params = True:Before (base branch) — provider rejects the forwarded param:
After (this branch) — params dropped, request succeeds:
The same asymmetry was reproduced through a full proxy deployment (litellm 1.94.0 on the stock docker image) in #35053, including the silent-downgrade behavior when
router_settings.fallbacksare configured — full 16-param × 2-endpoint × 2-generation sweep table there.Unit tests:
tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_request_optional_param_utils.py— drop forsupports_sampling_params: falsemodels (bare andvertex_ai/-prefixed ids), keep for supporting models,temperature=1allowed, cleanUnsupportedParamsErrorwithoutdrop_params.tests/test_litellm/llms/anthropic/locally: 1184 passed vs 1179 on base, same 41 pre-existing env-dependent failures in both runs.