Skip to content

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]

#14404 BugFix - Add support for Azure AD token-based authorization in image generation request headers definition for Azure

Shagun Bansal589c83b88b45
diff --git a/litellm/llms/azure/azure.py b/litellm/llms/azure/azure.py
index 5ee9065f5e1..f41a9bea0c9 100644
--- a/litellm/llms/azure/azure.py
+++ b/litellm/llms/azure/azure.py
@@ -1117,6 +1117,14 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM):
status_code=422, message="max retries must be an int"
)
+ if api_key is None and azure_ad_token_provider is not None:
+ azure_ad_token = azure_ad_token_provider()
+ if azure_ad_token:
+ headers.pop(
+ "api-key", None
+ )
+ headers["Authorization"] = f"Bearer {azure_ad_token}"
+
# init AzureOpenAI Client
azure_client_params: Dict[str, Any] = self.initialize_azure_sdk_client(
litellm_params=litellm_params or {},