Repository navigation
fix(anthropic): drop unsupported speed param with drop_params - #31152
krrish-berri-2 merged 4 commits into
Conversation
Anthropic fast mode (speed) is Opus 4.6/4.7/4.8 on the direct API only. Strip speed when the model map lacks supports_speed and drop_params is set, for both chat completions and /v1/messages passthrough. Co-authored-by: Cursor <cursoragent@cursor.com>
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes Anthropic API 400 errors when callers pass
Confidence Score: 5/5Safe to merge. The change is well-scoped: it only affects requests that include a The fix correctly reads capability data from the model cost JSON rather than hardcoding model names in Python, both paths (chat completions and No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/common_utils.py | Adds _get_exact_model_capability – a deliberate non-alias-walking counterpart to _get_model_capability – used to gate speed on the exact model-map entry only, preventing Bedrock/Vertex prefix-stripped names from accidentally resolving to a fast-mode-capable direct-API entry. |
| litellm/llms/anthropic/chat/transformation.py | Adds _model_supports_speed_param and _maybe_drop_speed_param; calls the latter inside the speed branch of map_openai_params (emits warning and pops on drop, raises on no-drop) and again in transform_request as a safety net for speed injected outside the normal param-mapping flow. |
| litellm/llms/anthropic/experimental_pass_through/messages/utils.py | Extends get_requested_anthropic_messages_optional_param with keyword-only model, drop_params, and custom_llm_provider params; delegates to _maybe_drop_speed_param so the passthrough path raises or strips speed consistently with the chat path. |
| litellm/llms/anthropic/experimental_pass_through/messages/handler.py | Wires model, drop_params, and custom_llm_provider through to get_requested_anthropic_messages_optional_param; change is minimal and correct. |
| model_prices_and_context_window.json | Adds supports_speed: true exactly to the five direct-API Anthropic Opus entries (claude-opus-4-6, claude-opus-4-6-20260205, claude-opus-4-7, claude-opus-4-7-20260416, claude-opus-4-8). Bedrock, Vertex, Azure, and other provider-specific entries are intentionally left unchanged. |
| litellm/model_prices_and_context_window_backup.json | Mirrors the same five supports_speed: true additions as the primary JSON; both files stay in sync. |
| tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py | Adds tests for supported/rejected models, provider-gating (vertex_ai/azure_ai/bedrock), drop_params=True strips unsupported speed, drop_params=False raises UnsupportedParamsError; existing test_fast_mode_parameter_mapping is unchanged and continues to verify speed passes through for Opus models. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_messages_speed.py | New test file covering the passthrough /v1/messages path: drops speed for non-Opus, keeps it for Opus, raises when drop_params=False, and verifies vertex_ai Opus is also blocked. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_request_optional_param_utils.py | Extends existing regression tests for the param-filter fast path with two new cases verifying global litellm.drop_params behaviour in the utils layer. |
| tests/test_litellm/test_utils.py | Adds supports_speed to the JSON schema validator so the new field is recognized as a valid boolean key; no logic changes. |
Reviews (3): Last reviewed commit: "fix(anthropic): gate speed param by rout..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7cc14505f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The new supports_speed flag on Opus entries must pass JSON schema validation in test_aaamodel_prices_and_context_window_json_is_valid. Co-authored-by: Cursor <cursoragent@cursor.com>
Passthrough /v1/messages now raises UnsupportedParamsError when speed is unsupported and drop_params is false. Emit drop warning from map_openai_params when speed is silently skipped. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@greptile review |
Vertex, Azure, and Bedrock reuse the shared Anthropic transform and strip their provider prefix first, so a bare `claude-opus-4-8` resolved to the direct-API model-map entry (`supports_speed: true`) and forwarded `speed` upstream, producing the same 400 that drop_params is meant to prevent. Gate fast mode on `custom_llm_provider == "anthropic"` so it stays on the direct Anthropic API across both the chat completions and `/v1/messages` passthrough paths, and collapse the duplicated drop/raise logic in map_openai_params into the shared `_maybe_drop_speed_param` helper.
|
@greptileai review Generated by Claude Code |
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit bc36f4a. Configure here.
Relevant issues
Fixes requests to Anthropic models that do not support fast mode (e.g.
claude-sonnet-4-6) failing with a 400 when callers passspeedand havedrop_paramsenabledPre-Submission checklist
make test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
With
drop_params=True,/v1/messagesto a non-Opus model no longer forwardsspeedto Anthropic.Unit tests:
LITELLM_LOCAL_MODEL_COST_MAP=True python -m pytest \ tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py -k "speed or fast_mode" \ tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_messages_speed.py \ tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_request_optional_param_utils.py -qType
🐛 Bug Fix
Changes
Anthropic fast mode (
speed) is a research preview on the direct Claude API only, for Opus 4.6, 4.7, and 4.8. It is not available on Bedrock, Vertex, or Azure Foundry.This PR gates
speedon a newsupports_speedflag in the model map, scoped to the direct Anthropic provider. The lookup reads the exact routed model-map entry (no provider alias walk). Vertex, Azure, and Bedrock reuse the shared Anthropic transform after stripping their provider prefix, so a bareclaude-opus-4-8arriving from one of those routes would otherwise resolve to the fast-mode-capable direct entry and forwardspeedupstream; the gate now also checkscustom_llm_providerso those routes are kept out. When the model does not supportspeedandlitellm.drop_paramsor per-requestdrop_paramsis true,speedis stripped before the upstream request on both the chat completions path and the/v1/messagespassthrough. Whendrop_paramsis false, anUnsupportedParamsErroris raised instead.Model map entries updated for
claude-opus-4-6,claude-opus-4-6-20260205,claude-opus-4-7,claude-opus-4-7-20260416, andclaude-opus-4-8in bothmodel_prices_and_context_window.jsonand the bundled backup. Bedrock/Vertex/Azure Opus entries are intentionally unchanged.Made with Cursor