Repository navigation
fix(anthropic_messages): gate sampling params on /v1/messages like /chat/completions #37868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
2fb3acb
1a408d7
c0118e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,13 +44,30 @@ def get_requested_anthropic_messages_optional_param( | |
| filtered_params: Final = {k: v for k, v in params.items() if k in valid_keys and v is not None} | ||
| if model is not None: | ||
| from litellm.llms.anthropic.chat.transformation import AnthropicConfig | ||
| from litellm.llms.anthropic.common_utils import AnthropicModelInfo | ||
|
|
||
| AnthropicConfig._maybe_drop_speed_param( | ||
| model=model, | ||
| optional_params=filtered_params, | ||
| drop_params=drop_params, | ||
| custom_llm_provider=custom_llm_provider, | ||
| ) | ||
| # Claude 4.7+ removed sampling params (the API 400s on top_p, top_k, | ||
| # and any temperature other than 1). Mirror the /chat/completions | ||
| # gating — drop under drop_params, else raise a clean client-side | ||
| # 400 — instead of forwarding a known-rejected param upstream, where | ||
| # router fallbacks would mask the provider 400 as a silent model | ||
| # downgrade. | ||
| for param in ("temperature", "top_p", "top_k"): | ||
| if param in filtered_params: | ||
| AnthropicModelInfo._apply_sampling_param( # pyright: ignore[reportPrivateUsage] # same gating the /chat/completions path applies; forking it would drift | ||
| optional_params=filtered_params, | ||
| model=model, | ||
| param=param, | ||
| value=filtered_params.pop(param), | ||
| drop_params=drop_params, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Context Used: CLAUDE.md (source)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The chat path does the same pop-then-reapply for top_k in transformation.py. The helper only writes back supported params, so the pop is required.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. Apologies for the noise. |
||
| output_key=param, | ||
| ) | ||
| return cast(AnthropicMessagesRequestOptionalParams, filtered_params) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.