The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(proxy): forward a client's anthropic-beta and anthropic-version headers to bedrock_mantle
mateo-berric13dcb0abfe3
diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.pyindex 9a973755894..e415a78f412 100644--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@ -3418,7 +3418,12 @@ async def add_guardrails_from_policy_engine(_ANTHROPIC_API_HEADER_PROVIDERS: Final = ",".join(- (LlmProviders.ANTHROPIC.value, LlmProviders.BEDROCK.value, LlmProviders.VERTEX_AI.value)+ (+ LlmProviders.ANTHROPIC.value,+ LlmProviders.BEDROCK.value,+ LlmProviders.BEDROCK_MANTLE.value,+ LlmProviders.VERTEX_AI.value,+ ))_ANTHROPIC_OAUTH_CREDENTIAL_PROVIDERS: Final = LlmProviders.ANTHROPIC.valuediff --git a/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_messages_transformation.py b/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_messages_transformation.pyindex 3544262996c..6bacf8f3d94 100644--- a/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_messages_transformation.py+++ b/tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_messages_transformation.py@@ -385,6 +385,25 @@ class TestBetaHeadersOnTheWire:"interleaved-thinking-2025-05-14",]+ @pytest.mark.asyncio+ @respx.mock+ async def test_betas_a_proxy_client_sends_reach_mantle_filtered(self):+ from litellm.proxy.litellm_pre_call_utils import add_provider_specific_headers_to_request++ proxy_request_data: dict = {}+ add_provider_specific_headers_to_request(+ data=proxy_request_data,+ headers={+ "anthropic-beta": "claude-code-20250219,fast-mode-2026-02-01,interleaved-thinking-2025-05-14",+ "anthropic-version": "2023-06-01",+ "user-agent": "claude-cli/2.1.239",+ },+ )++ route = await self._send(**proxy_request_data)++ assert _sent_betas(route) == ["claude-code-20250219", "interleaved-thinking-2025-05-14"]+@pytest.mark.asyncio@respx.mockasync def test_betas_mantle_rejects_are_dropped_before_the_request(self):diff --git a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py b/tests/test_litellm/proxy/test_litellm_pre_call_utils.pyindex 88d38d74f49..9257a2dd23d 100644--- a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py+++ b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py@@ -7249,7 +7249,7 @@ CROSS_ACCOUNT_AUTHORIZATION = "Bearer deliberately-configured-pass-through-tokenSIGV4_PREFIX = "AWS4-HMAC-SHA256"AUTHORIZATION_HEADER_CASINGS = ["authorization", "Authorization", "AUTHORIZATION"]-LEAK_TARGET_PROVIDERS = ["bedrock", "bedrock_converse", "vertex_ai"]+LEAK_TARGET_PROVIDERS = ["bedrock", "bedrock_converse", "bedrock_mantle", "vertex_ai"]BEDROCK_ENDPOINT = ("https://bedrock-runtime.us-west-2.amazonaws.com/model/us.anthropic.claude-sonnet-4-5-20250929-v1:0/invoke"@@ -7342,6 +7342,28 @@ def test_oauth_credential_entry_is_scoped_to_anthropic_alone():assert [entry["custom_llm_provider"] for entry in credential_entries] == ["anthropic"][email protected]("custom_llm_provider", ["anthropic", "bedrock", "bedrock_mantle", "vertex_ai"])+def test_client_anthropic_api_headers_reach_every_anthropic_messages_provider(custom_llm_provider):+ client_headers = {+ "anthropic-beta": "claude-code-20250219,interleaved-thinking-2025-05-14",+ "anthropic-version": "2023-06-01",+ "user-agent": "claude-cli/2.1.239",+ }++ forwarded = _headers_forwarded_to(client_headers, custom_llm_provider)++ assert forwarded == {+ "anthropic-beta": "claude-code-20250219,interleaved-thinking-2025-05-14",+ "anthropic-version": "2023-06-01",+ }+++def test_client_anthropic_api_headers_stay_off_openai_compatible_providers():+ forwarded = _headers_forwarded_to({"anthropic-beta": "claude-code-20250219"}, "openai")++ assert forwarded == {}++def test_no_provider_specific_header_when_client_sends_nothing_anthropic():data: dict = {}add_provider_specific_headers_to_request(