From a2793bdb5760cb75f4eb944da9d7f0813c128dbb Mon Sep 17 00:00:00 2001 From: Shagun Bansal Date: Tue, 23 Sep 2025 18:49:37 +0530 Subject: [PATCH 1/3] #14404 BugFix - Add support for Azure AD token-based authorization in image generation request headers definition for Azure --- litellm/images/main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/litellm/images/main.py b/litellm/images/main.py index 2a8b62bce24..0e11d9d3e56 100644 --- a/litellm/images/main.py +++ b/litellm/images/main.py @@ -314,6 +314,15 @@ def image_generation( # noqa: PLR0915 "Content-Type": "application/json", "api-key": api_key, } + + if api_key is None and azure_ad_token_provider is not None: + azure_ad_token = azure_ad_token_provider() + if azure_ad_token: + default_headers.pop( + "api-key", None + ) + default_headers["Authorization"] = f"Bearer {azure_ad_token}" + for k, v in default_headers.items(): if k not in headers: headers[k] = v From 250e13ea928c79e8d6882f1014914d2899337d16 Mon Sep 17 00:00:00 2001 From: Shagun Bansal Date: Wed, 24 Sep 2025 16:23:20 +0530 Subject: [PATCH 2/3] Revert "#14404 BugFix - Add support for Azure AD token-based authorization in image generation request headers definition for Azure" This reverts commit a2793bdb5760cb75f4eb944da9d7f0813c128dbb. --- litellm/images/main.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/litellm/images/main.py b/litellm/images/main.py index 0e11d9d3e56..2a8b62bce24 100644 --- a/litellm/images/main.py +++ b/litellm/images/main.py @@ -314,15 +314,6 @@ def image_generation( # noqa: PLR0915 "Content-Type": "application/json", "api-key": api_key, } - - if api_key is None and azure_ad_token_provider is not None: - azure_ad_token = azure_ad_token_provider() - if azure_ad_token: - default_headers.pop( - "api-key", None - ) - default_headers["Authorization"] = f"Bearer {azure_ad_token}" - for k, v in default_headers.items(): if k not in headers: headers[k] = v From 589c83b88b45b53dd5c6bce05ace5dd1245188e8 Mon Sep 17 00:00:00 2001 From: Shagun Bansal Date: Wed, 24 Sep 2025 16:25:44 +0530 Subject: [PATCH 3/3] #14404 BugFix - Add support for Azure AD token-based authorization in image generation request headers definition for Azure --- litellm/llms/azure/azure.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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 {},