fix(bedrock): Filter anthropic-beta header for Bedrock passthrough#20012
fix(bedrock): Filter anthropic-beta header for Bedrock passthrough#20012brian-lai wants to merge 1 commit intoBerriAI:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
029d04e to
29af1bb
Compare
29af1bb to
73f66ea
Compare
|
💣 We are having the same issues when using the claude-code action through litellm; we are running 1.81.3-nightly. |
AWS Bedrock only supports a specific whitelist of beta flags and rejects requests with "invalid beta flag" error for unsupported ones (e.g., mcp-servers-2025-12-04, oauth-2025-04-20 from Claude Code). This implements whitelist-based filtering in BedrockPassthroughConfig to filter the anthropic-beta header before signing and forwarding requests, consistent with the Invoke API approach in PR BerriAI#19877. Supported beta flags (per AWS docs): - computer-use-2024-10-22, computer-use-2025-01-24 - token-efficient-tools-2025-02-19 - interleaved-thinking-2025-05-14 - output-128k-2025-02-19 - dev-full-thinking-2025-05-14 - context-1m-2025-08-07 - context-management-2025-06-27 - effort-2025-11-24 - tool-search-tool-2025-10-19 - tool-examples-2025-10-29 Fixes: BerriAI#16726 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
73f66ea to
e91c0fd
Compare
Greptile OverviewGreptile SummaryFilters unsupported Key Changes
Impact
Test Coverage
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/passthrough/transformation.py | Added whitelist-based filtering for anthropic-beta headers to prevent "invalid beta flag" errors from Bedrock |
| tests/test_litellm/llms/bedrock/passthrough/test_bedrock_header_filtering.py | Comprehensive test suite covering all filtering scenarios including edge cases and case-insensitive matching |
Sequence Diagram
sequenceDiagram
participant CC as Claude Code
participant LP as LiteLLM Proxy
participant BPC as BedrockPassthroughConfig
participant AWS as AWS Bedrock
CC->>LP: POST /bedrock/messages<br/>Headers: anthropic-beta: oauth-2025-04-20,mcp-servers-2025-12-04
LP->>BPC: sign_request(headers, ...)
BPC->>BPC: _filter_anthropic_beta_header(headers)
Note over BPC: Parse comma-separated values<br/>Filter against BEDROCK_SUPPORTED_BETAS<br/>oauth-2025-04-20 ❌ (unsupported)<br/>mcp-servers-2025-12-04 ❌ (unsupported)<br/>Header omitted (no supported betas remain)
BPC->>BPC: _sign_request(filtered_headers, ...)
Note over BPC: Sign request with AWS SigV4<br/>(without anthropic-beta header)
BPC-->>LP: Signed headers + body
LP->>AWS: POST /model/.../invoke<br/>(No anthropic-beta header)
AWS-->>LP: 200 OK (Success)
LP-->>CC: 200 OK (Success)
|
The lint failure is a pre-existing issue in Could this be merged despite the CI failure? The actual fix here is correct and tested. |
|
@hunterchris if you're still waiting for this PR to get merged in, try https://github.com/brian-lai/anthropic-beta-stripping-proxy you can easily set this up wherever you're running your nightly execution of claude code and have claude-code hit the local proxy instead. that will strip ALL beta headers from the request before it gets to litellm you don't necessarily have to use the repo, but the pattern is simple and easily adaptable for any setup |
|
While we started by striping headers manually in Istio, we now have a much longer term solution for our company.. My PR includes a commit that centralizes and fixes definitely the header stripping issue by setting up a straightforward system that blocks beta headers by default, and then allows beta headers based on the specifics models called & its support. |
Summary
anthropic-betaheader from requests before forwarding to AWS BedrockProblem
When using Claude Code with LiteLLM as a proxy to AWS Bedrock, requests fail with:
{"message":"invalid beta flag"}This happens because Claude Code sends
anthropic-beta: oauth-2025-04-20(or other beta values) headers, which AWS Bedrock doesn't recognize or support.Solution
Filter the
anthropic-betaheader (case-insensitively) inBedrockPassthroughConfig.sign_request()before the request is signed and forwarded to Bedrock.Key points:
Anthropic-Beta,ANTHROPIC-BETA, etc.anthropic-versionare preservedTest plan
Run tests:
Related
🤖 Generated with Claude Code