Skip to content

fix(anthropic): drop unsupported speed param with drop_params - #31152

Merged
krrish-berri-2 merged 4 commits into
litellm_internal_stagingfrom
litellm_fix_anthropic_speed_drop_params
Jun 24, 2026
Merged

krrish-berri-2 merged 4 commits into
litellm_internal_stagingfrom
litellm_fix_anthropic_speed_drop_params

Conversation

@krrish-berri-2

@krrish-berri-2 krrish-berri-2 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

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 pass speed and have drop_params enabled

Pre-Submission checklist

  • I have added meaningful tests
  • 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

Screenshots / Proof of Fix

With drop_params=True, /v1/messages to a non-Opus model no longer forwards speed to Anthropic.

# start proxy (separate terminal)
python litellm/proxy/proxy_cli.py --config litellm/proxy/dev_config.yaml --detailed_debug --reload --use_v2_migration_resolver

# before fix: Anthropic 400 "speed: Extra inputs are not permitted"
# after fix: request succeeds; speed is dropped with a verbose warning
curl -s http://localhost:4000/v1/messages \
  -H "Authorization: Bearer sk-1234" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-6",
    "max_tokens": 16,
    "messages": [{"role": "user", "content": "hi"}],
    "speed": "fast"
  }' | jq .

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 -q

Type

🐛 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 speed on a new supports_speed flag 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 bare claude-opus-4-8 arriving from one of those routes would otherwise resolve to the fast-mode-capable direct entry and forward speed upstream; the gate now also checks custom_llm_provider so those routes are kept out. When the model does not support speed and litellm.drop_params or per-request drop_params is true, speed is stripped before the upstream request on both the chat completions path and the /v1/messages passthrough. When drop_params is false, an UnsupportedParamsError is 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, and claude-opus-4-8 in both model_prices_and_context_window.json and the bundled backup. Bedrock/Vertex/Azure Opus entries are intentionally unchanged.

Made with Cursor

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>
@CLAassistant

CLAassistant commented Jun 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mateo-berri
❌ krrish-berri-2
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Anthropic API 400 errors when callers pass speed to models that don't support fast mode (e.g. claude-sonnet-4-6) and have drop_params enabled. It gates the speed parameter behind a new supports_speed flag in the model cost map, read via an exact-lookup helper that deliberately skips provider-alias walking so Bedrock/Vertex/Azure Opus entries cannot inherit the flag from the direct-API entry.

  • Adds _get_exact_model_capability / _model_supports_speed_param / _maybe_drop_speed_param to AnthropicConfig; the drop-or-raise logic is invoked in both map_openai_params and (as a safety net) transform_request, and is also wired into the /v1/messages passthrough path via get_requested_anthropic_messages_optional_param.
  • Sets supports_speed: true on exactly five direct-API Opus entries (claude-opus-4-6, claude-opus-4-6-20260205, claude-opus-4-7, claude-opus-4-7-20260416, claude-opus-4-8) in both the primary and backup JSON; all Bedrock/Vertex/Azure variants are intentionally left unchanged.
  • Test coverage spans both paths (chat completions and passthrough), both drop_params states (drop vs. raise), and the Vertex/Azure/Bedrock provider-gating regression.

Confidence Score: 5/5

Safe to merge. The change is well-scoped: it only affects requests that include a speed parameter, and only for models that don't support fast mode. Existing Opus callers with speed on the direct Anthropic API are unaffected; all other providers are correctly blocked at the custom_llm_provider check before any model-map lookup occurs.

The fix correctly reads capability data from the model cost JSON rather than hardcoding model names in Python, both paths (chat completions and /v1/messages passthrough) are handled, and the provider guard prevents the Bedrock/Vertex/Azure prefix-stripping bypass. No existing tests were weakened, and the new tests cover the full decision matrix.

No files require special attention.

Important Files Changed

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

Comment thread litellm/llms/anthropic/experimental_pass_through/messages/utils.py
Comment thread litellm/llms/anthropic/chat/transformation.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread litellm/llms/anthropic/chat/transformation.py
krrish-berri-2 and others added 2 commits June 23, 2026 18:34
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>
@krrish-berri-2

Copy link
Copy Markdown
Contributor Author

@greptile review

@krrish-berri-2
krrish-berri-2 enabled auto-merge (squash) June 24, 2026 01:57
@mateo-berri
mateo-berri self-requested a review June 24, 2026 04:45
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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai review


Generated by Claude Code

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks!

@krrish-berri-2
krrish-berri-2 merged commit d0706c1 into litellm_internal_staging Jun 24, 2026
124 checks passed
@krrish-berri-2
krrish-berri-2 deleted the litellm_fix_anthropic_speed_drop_params branch June 24, 2026 05:22
@ishaan-berri ishaan-berri mentioned this pull request Jun 25, 2026
9 of 13 tasks
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.

3 participants