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 auth issue
Sameer Kankuteafe540e88d76
diff --git a/litellm/llms/azure/anthropic/transformation.py b/litellm/llms/azure/anthropic/transformation.pyindex 81beeb74ae1..9bc4f130563 100644--- a/litellm/llms/azure/anthropic/transformation.py+++ b/litellm/llms/azure/anthropic/transformation.py@@ -1,11 +1,10 @@"""Azure Anthropic transformation config - extends AnthropicConfig with Azure authentication"""-from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union+from typing import TYPE_CHECKING, Dict, List, Optional, Union-import litellmfrom litellm.llms.anthropic.chat.transformation import AnthropicConfig-from litellm.llms.azure.common_utils import BaseAzureLLM, get_azure_ad_token+from litellm.llms.azure.common_utils import BaseAzureLLMfrom litellm.types.llms.openai import AllMessageValuesfrom litellm.types.router import GenericLiteLLMParams@@ -56,6 +55,11 @@ class AzureAnthropicConfig(AnthropicConfig):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")# Get tools and other anthropic-specific setuptools = optional_params.get("tools")@@ -81,10 +85,6 @@ class AzureAnthropicConfig(AnthropicConfig):user_anthropic_beta_headers=user_anthropic_beta_headers,mcp_server_used=mcp_server_used,)-- # Remove x-api-key from anthropic headers since Azure uses different auth- anthropic_headers.pop("x-api-key", None)-# Merge headers - Azure auth (api-key or Authorization) takes precedenceheaders = {**anthropic_headers, **headers}diff --git a/litellm/main.py b/litellm/main.pyindex 4857f1b9754..c155dc31db3 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -2379,10 +2379,18 @@ def completion( # type: ignore # noqa: PLR0915)# Ensure the URL ends with /v1/messages- if not api_base.endswith("/v1/messages"):- if not api_base.endswith("/anthropic"):- api_base = api_base.rstrip("/") + "/anthropic"- api_base = api_base.rstrip("/") + "/v1/messages"+ api_base = api_base.rstrip("/")+ if api_base.endswith("/v1/messages"):+ pass+ elif api_base.endswith("/anthropic/v1/messages"):+ pass+ else:+ if "/anthropic" in api_base:+ parts = api_base.split("/anthropic", 1)+ api_base = parts[0] + "/anthropic"+ else:+ api_base = api_base + "/anthropic"+ api_base = api_base + "/v1/messages"response = azure_anthropic_chat_completions.completion(model=model,diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex 351e01bc45e..bc1a1950664 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -1087,6 +1087,60 @@"output_cost_per_token": 1.5e-05,"supports_function_calling": true},+ "azure/claude-haiku-4-5": {+ "input_cost_per_token": 1e-06,+ "litellm_provider": "azure_anthropic",+ "max_input_tokens": 200000,+ "max_output_tokens": 64000,+ "max_tokens": 64000,+ "mode": "chat",+ "output_cost_per_token": 5e-06,+ "supports_assistant_prefill": true,+ "supports_computer_use": true,+ "supports_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },+ "azure/claude-opus-4-1": {+ "input_cost_per_token": 1.5e-05,+ "litellm_provider": "azure_anthropic",+ "max_input_tokens": 200000,+ "max_output_tokens": 32000,+ "max_tokens": 32000,+ "mode": "chat",+ "output_cost_per_token": 7.5e-05,+ "supports_assistant_prefill": true,+ "supports_computer_use": true,+ "supports_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },+ "azure/claude-sonnet-4-5": {+ "input_cost_per_token": 3e-06,+ "litellm_provider": "azure_anthropic",+ "max_input_tokens": 200000,+ "max_output_tokens": 64000,+ "max_tokens": 64000,+ "mode": "chat",+ "output_cost_per_token": 1.5e-05,+ "supports_assistant_prefill": true,+ "supports_computer_use": true,+ "supports_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },"azure/computer-use-preview": {"input_cost_per_token": 3e-06,"litellm_provider": "azure",diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex 351e01bc45e..bc1a1950664 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -1087,6 +1087,60 @@"output_cost_per_token": 1.5e-05,"supports_function_calling": true},+ "azure/claude-haiku-4-5": {+ "input_cost_per_token": 1e-06,+ "litellm_provider": "azure_anthropic",+ "max_input_tokens": 200000,+ "max_output_tokens": 64000,+ "max_tokens": 64000,+ "mode": "chat",+ "output_cost_per_token": 5e-06,+ "supports_assistant_prefill": true,+ "supports_computer_use": true,+ "supports_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },+ "azure/claude-opus-4-1": {+ "input_cost_per_token": 1.5e-05,+ "litellm_provider": "azure_anthropic",+ "max_input_tokens": 200000,+ "max_output_tokens": 32000,+ "max_tokens": 32000,+ "mode": "chat",+ "output_cost_per_token": 7.5e-05,+ "supports_assistant_prefill": true,+ "supports_computer_use": true,+ "supports_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },+ "azure/claude-sonnet-4-5": {+ "input_cost_per_token": 3e-06,+ "litellm_provider": "azure_anthropic",+ "max_input_tokens": 200000,+ "max_output_tokens": 64000,+ "max_tokens": 64000,+ "mode": "chat",+ "output_cost_per_token": 1.5e-05,+ "supports_assistant_prefill": true,+ "supports_computer_use": true,+ "supports_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },"azure/computer-use-preview": {"input_cost_per_token": 3e-06,"litellm_provider": "azure",