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(anthropic): detect client credential headers case-insensitively on /v1/messages
mateo-berric449f114513a
diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.pyindex 75146922a39..ebd514c2605 100644--- a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py+++ b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py@@ -308,7 +308,8 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):# Check for Anthropic OAuth token in Authorization headerheaders, api_key = optionally_handle_anthropic_oauth(headers=headers, api_key=api_key)- if "x-api-key" not in headers and "authorization" not in headers:+ header_names: Final = frozenset(name.lower() for name in headers)+ if "x-api-key" not in header_names and "authorization" not in header_names:auth_header: Final = AnthropicModelInfo.get_auth_header(api_key)if auth_header is None:raise AuthenticationError(diff --git a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.pyindex a96c44ac5c0..0a86bcfe85a 100644--- a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py+++ b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py@@ -1249,8 +1249,9 @@ class TestPassthroughAuthToken:api_base=None,)- def test_passthrough_client_x_api_key_header_is_kept(self):- """A client-forwarded x-api-key header should satisfy validation without env credentials."""+ @pytest.mark.parametrize("header_name", ["x-api-key", "X-Api-Key", "X-API-KEY"])+ def test_passthrough_client_x_api_key_header_is_kept(self, header_name):+ """A client-forwarded x-api-key header, whatever its casing, should satisfy validation without env credentials."""from unittest.mock import patch as mock_patchfrom litellm.llms.anthropic.experimental_pass_through.messages.transformation import (@@ -1260,7 +1261,7 @@ class TestPassthroughAuthToken:config = AnthropicMessagesConfig()with mock_patch.dict("os.environ", {}, clear=True):updated_headers, _ = config.validate_anthropic_messages_environment(- headers={"x-api-key": FAKE_REGULAR_KEY},+ headers={header_name: FAKE_REGULAR_KEY},model="claude-sonnet-4-5-20250929",messages=[{"role": "user", "content": "Hello"}],optional_params={},@@ -1269,7 +1270,8 @@ class TestPassthroughAuthToken:api_base=None,)- assert updated_headers["x-api-key"] == FAKE_REGULAR_KEY+ assert [name for name in updated_headers if name.lower() == "x-api-key"] == [header_name]+ assert updated_headers[header_name] == FAKE_REGULAR_KEYdef test_passthrough_get_complete_url_honours_base_url_env(self):"""get_complete_url should use ANTHROPIC_BASE_URL when api_base is None."""