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 authentication errors at messages API via azure_ai
Daniel Kruegerd7468dab7e81
diff --git a/litellm/llms/azure_ai/anthropic/messages_transformation.py b/litellm/llms/azure_ai/anthropic/messages_transformation.pyindex 73dc84167ab..55818cc07d6 100644--- a/litellm/llms/azure_ai/anthropic/messages_transformation.py+++ b/litellm/llms/azure_ai/anthropic/messages_transformation.py@@ -48,7 +48,12 @@ class AzureAnthropicMessagesConfig(AnthropicMessagesConfig):headers = BaseAzureLLM._base_validate_azure_environment(headers=headers, litellm_params=litellm_params_obj)-++ # Azure Anthropic uses x-api-key header (not api-key)+ # Convert api-key to x-api-key if present+ if "api-key" in headers and "x-api-key" not in headers:+ headers["x-api-key"] = headers.pop("api-key")+# Set anthropic-version headerif "anthropic-version" not in headers:headers["anthropic-version"] = "2023-06-01"diff --git a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.py b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.pyindex d78a638fd89..bdced849c7e 100644--- a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.py+++ b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_messages_transformation.py@@ -55,11 +55,12 @@ class TestAzureAnthropicMessagesConfig:assert isinstance(call_args[1]["litellm_params"], GenericLiteLLMParams)assert call_args[1]["litellm_params"].api_key == "test-api-key"assert "anthropic-version" in result- # api-key header is preserved as-is (no conversion to x-api-key)- assert "api-key" in result+ assert "x-api-key" in result+ assert result["x-api-key"] == "test-api-key"+ assert "api-key" not in result- def test_validate_anthropic_messages_environment_preserves_api_key_header(self):- """Test that api-key header is preserved as-is (Azure handles the header internally)"""+ def test_validate_anthropic_messages_environment_converts_api_key_to_x_api_key(self):+ """Test that api-key header is converted to x-api-key"""config = AzureAnthropicMessagesConfig()headers = {}model = "claude-sonnet-4-5"@@ -79,9 +80,10 @@ class TestAzureAnthropicMessagesConfig:litellm_params=litellm_params,)- # Verify api-key header is preserved as-is- assert "api-key" in result- assert result["api-key"] == "test-api-key"+ # Verify api-key was converted to x-api-key+ assert "x-api-key" in result+ assert result["x-api-key"] == "test-api-key"+ assert "api-key" not in resultdef test_validate_anthropic_messages_environment_sets_headers(self):"""Test that required headers are set"""@@ -108,8 +110,7 @@ class TestAzureAnthropicMessagesConfig:assert result["anthropic-version"] == "2023-06-01"assert "content-type" in resultassert result["content-type"] == "application/json"- # api-key header is preserved as-is- assert "api-key" in result+ assert "x-api-key" in resultdef test_get_complete_url_with_base_url(self):"""Test get_complete_url with base URL"""