[Fix] Forward anthropic-beta headers to Bedrock and other anthropic providers #15623
+225
−54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
[Fix] Forward anthropic-beta headers to Bedrock and other cross-providers
Relevant issues
Fixes:
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🐛 Bug Fix
Changes
Problem
The
ProviderSpecificHeadermechanism in the LiteLLM proxy was only supporting single provider matching. When users sent requests withanthropic-betaheaders (e.g.,context-1m-2025-08-07for extended context windows) through the proxy to AWS Bedrock, the headers were not forwarded because:custom_llm_provider="anthropic"custom_llm_provider="bedrock"This affected any cross-provider header scenarios where the same header needs to work across multiple providers (Anthropic, Bedrock, Vertex AI, etc.).
Solution
Enhanced the
ProviderSpecificHeadermechanism to support multiple providers using a comma-separated format:1. Updated
add_provider_specific_headers_to_request()inlitellm/proxy/litellm_pre_call_utils.py:custom_llm_provider="anthropic,bedrock,bedrock_converse,vertex_ai"2. Updated
get_provider_specific_headers()inlitellm/litellm_core_utils/get_provider_specific_headers.py:3. Added comprehensive test coverage:
tests/test_litellm/litellm_core_utils/test_provider_specific_headers.pytests/proxy_unit_tests/test_proxy_utils.pyTest Results
All 8 tests passing (100% success rate):
Impact
anthropic-betaheaders through the proxy and have them correctly forwarded to BedrockFiles Modified
litellm/proxy/litellm_pre_call_utils.py(lines 1187-1207)litellm/litellm_core_utils/get_provider_specific_headers.py(lines 6-29)tests/test_litellm/litellm_core_utils/test_provider_specific_headers.py(new tests added)tests/proxy_unit_tests/test_proxy_utils.py(tests updated and added)