mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-18 06:26:16 +00:00
Merge pull request #18500 from systec-dk/fix_anthropic
fix authentication errors at messages API via azure_ai
This commit is contained in:
@@ -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 header
|
||||
if "anthropic-version" not in headers:
|
||||
headers["anthropic-version"] = "2023-06-01"
|
||||
|
||||
+10
-9
@@ -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 result
|
||||
|
||||
def 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 result
|
||||
assert result["content-type"] == "application/json"
|
||||
# api-key header is preserved as-is
|
||||
assert "api-key" in result
|
||||
assert "x-api-key" in result
|
||||
|
||||
def test_get_complete_url_with_base_url(self):
|
||||
"""Test get_complete_url with base URL"""
|
||||
|
||||
Reference in New Issue
Block a user