Skip to content

fix(bedrock): keep filtering anthropic-beta headers on the Claude platform messages path - #42260

Closed
yuneng-berri wants to merge 1 commit into
mainfrom
litellm_bedrock_claude_platform_beta_filter
Closed

yuneng-berri wants to merge 1 commit into
mainfrom
litellm_bedrock_claude_platform_beta_filter

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

Summary

BedrockClaudePlatformMessagesConfig silently stopped filtering anthropic-beta headers, so betas Bedrock does not accept are now forwarded verbatim to it.

#42152 added an override to AnthropicMessagesConfig:

def should_filter_anthropic_beta_headers(self) -> bool:
    return self._resolved_provider != "anthropic"

That is correct for its own case — when the upstream really is api.anthropic.com, betas should pass through untouched. But AnthropicMessagesConfig.custom_llm_provider is a hardcoded property returning "anthropic", and _resolved_provider just reads it, so the method returns False for every subclass that does not override the provider.

BedrockClaudePlatformMessagesConfig overrides neither custom_llm_provider nor the filter, and nothing earlier in its MRO supplies a provider:

BedrockClaudePlatformMessagesConfig -> BedrockClaudePlatformMixin -> BaseAWSLLM
  -> SignsRequestsWithAWS -> AnthropicMessagesConfig

so it inherits "anthropic" and reports filter_betas=False. (The custom_llm_provider -> "bedrock" property in litellm/llms/bedrock/claude_platform/transformation.py belongs to the chat/converse config and is not in this MRO.)

This is the exact case the base class documents as needing the filter, in litellm/llms/base_llm/anthropic_messages/transformation.py:

Cross-provider translation paths (bedrock, vertex_ai, ...) need this so unsupported betas are dropped. Configs that forward natively to an Anthropic-compatible endpoint return False to pass betas through verbatim.

Before #42152 the base returned True, so Bedrock filtered. The filter runs at litellm/llms/custom_httpx/llm_http_handler.py:2281.

Sweep of every AnthropicMessages config — Bedrock is the only unintended False:

config provider filter_betas
AnthropicMessagesConfig anthropic False — intended, native
GithubCopilotAnthropicMessagesConfig github_copilot False — intended, explicit override
OpenAILikeAnthropicMessagesConfig anthropic False — intended, explicit override
AzureAnthropicMessagesConfig azure_ai True
MinimaxMessagesConfig minimax True
DeepSeekAnthropicMessagesConfig deepseek True
TencentAnthropicMessagesConfig tencent True
BedrockClaudePlatformMessagesConfig anthropic False — bug

Changes

  • BedrockClaudePlatformMessagesConfig opts back into the provider-scoped filter.
  • New coverage for Bedrock beta filtering — there was none, which is why this landed unnoticed.
  • The two passthrough tests whose contrast assertion caught this now compare against the Bedrock config, since a native-Anthropic False is intended behaviour.

I deliberately did not fix this by giving the config custom_llm_provider -> "bedrock". That would be the deeper fix, but _resolved_provider also feeds six model-capability lookups in AnthropicMessagesConfig (reasoning-effort translation, maybe_drop_disabled_thinking, adaptive-effort and thinking-temperature handling), so changing it would alter Bedrock thinking/reasoning behaviour in a regression fix. Worth doing separately, with its own testing.

Testing

Red/green against the new test, source fix removed then restored:

--- RED (fix removed)
FAILED tests/unit/llms/bedrock/claude_platform/...::test_bedrock_claude_platform_filters_anthropic_beta_headers
FAILED tests/unit/llms/github_copilot/...::test_github_copilot_config_disables_anthropic_beta_filtering
FAILED tests/unit/llms/openai_like/...::test_passthrough_disables_anthropic_beta_filtering
3 failed, 90 passed

--- GREEN (fix restored)
93 passed

Filtering demonstrably active again — an unsupported beta is dropped and a renamed one translated:

in:  code-execution-2025-08-25, advanced-tool-use-2025-11-20, context-management-2025-06-27
out: context-management-2025-06-27, tool-search-tool-2025-10-19
  • tests/unit/llms/{bedrock,github_copilot,openai_like} + test_llm_http_handler.py: 618 passed
  • Full tests/unit as CI runs it (-n 4 --dist=loadscope, 315 files): 6395 passed
  • scripts/pre_commit_lint.sh: PASS

How this was found

Triaging the #circleci-triage backlog. The two passthrough tests fail deterministically on main and CI had not yet run the unit job since #42152 merged, so the next scheduled run would have gone red on them. They read like stale assertions, but in each one the test's own subject still passes — the failing line is the contrast guard on the default, which is what surfaced the Bedrock leak.

…tform messages path

PR #42019's successor #42152 gave AnthropicMessagesConfig an override that
returns False when the resolved provider is "anthropic", so betas reach
api.anthropic.com verbatim. BedrockClaudePlatformMessagesConfig overrides
neither custom_llm_provider nor the filter, and nothing earlier in its MRO
supplies a provider, so it inherited "anthropic" and stopped filtering -
forwarding betas Bedrock does not accept, which the base class documents as
the exact case cross-provider paths need filtering for.

Opt the Claude platform config back into the provider-scoped filter and cover
it, since no test exercised Bedrock beta filtering before. The two passthrough
tests whose contrast assertion caught this now compare against the Bedrock
config, because a native-Anthropic False is intended.
@yuneng-berri
yuneng-berri requested a review from a team September 21, 2026 17:30
@codspeed

codspeed Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_bedrock_claude_platform_beta_filter (cac3628) with main (51ae7ab)

Open in CodSpeed

@codecov

codecov Bot commented Sep 21, 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 Sep 21, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with the Bedrock request path and regression coverage aligned with the intended filtering behavior

Summary

This PR restores Anthropic beta-header filtering for the Bedrock Claude platform Messages path

  • Adds an explicit filtering override to the Bedrock configuration
  • Adds regression coverage for the override and Bedrock-specific beta removal and renaming
  • Updates passthrough-provider tests to use Bedrock as the filtering-enabled contrast

Reviews (1) · Last reviewed commit: "fix(bedrock): keep filtering anthropic-b..."

@mateo-berri

Copy link
Copy Markdown
Contributor

Superseded by #42275, merged: filtering with the bedrock beta map 400s beta-gated requests on the Claude Platform route, which accepts every Anthropic beta

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.

2 participants