From b039374c718ecf7089ba74eca5a4aa95b6df6a09 Mon Sep 17 00:00:00 2001 From: Mubashir Osmani Date: Fri, 26 Sep 2025 16:35:35 -0400 Subject: [PATCH] Azure Managed Batches - api key error (#14932) * added qwen models and gpt-5-codex * fix flaky test * fix failing test * Added retries to prisma client state * fix: prisma client state retries in pods * Revert "fix failing test" This reverts commit dbec4988a2627257fd05b905e216225664517f32. * Revert "fix flaky test" This reverts commit b0ac2f2dc35ca433af0c82f3cda770d6981caff4. * Revert "added qwen models and gpt-5-codex" This reverts commit 9a8a8f2d47ab4dc8aecb0cd9a6a4f82ed81bb056. * Revert "fix: prisma client state retries in pods" This reverts commit 04e58e5ca1a489916e3b49e9b674f5c6713fd7cd. * fix lint * Revert "fix lint" This reverts commit 5303d52a5e3bee7e131dcabd098e94f0613a7bb9. * fixed lint * fix: azure api key managed batch files --- litellm/llms/azure/batches/handler.py | 8 ++++---- litellm/llms/azure/common_utils.py | 13 ++++++++++++- litellm/llms/azure/files/handler.py | 10 +++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/litellm/llms/azure/batches/handler.py b/litellm/llms/azure/batches/handler.py index 7fc6388ba87..c038f62561c 100644 --- a/litellm/llms/azure/batches/handler.py +++ b/litellm/llms/azure/batches/handler.py @@ -62,7 +62,7 @@ class AzureBatchesAPI(BaseAzureLLM): ) if azure_client is None: raise ValueError( - "OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: @@ -108,7 +108,7 @@ class AzureBatchesAPI(BaseAzureLLM): ) if azure_client is None: raise ValueError( - "OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: @@ -156,7 +156,7 @@ class AzureBatchesAPI(BaseAzureLLM): ) if azure_client is None: raise ValueError( - "OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) response = azure_client.batches.cancel(**cancel_batch_data) return response @@ -195,7 +195,7 @@ class AzureBatchesAPI(BaseAzureLLM): ) if azure_client is None: raise ValueError( - "OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: diff --git a/litellm/llms/azure/common_utils.py b/litellm/llms/azure/common_utils.py index 09b1888e04d..15569581eee 100644 --- a/litellm/llms/azure/common_utils.py +++ b/litellm/llms/azure/common_utils.py @@ -576,8 +576,19 @@ class BaseAzureLLM(BaseOpenAILLM): verbose_logger.debug( f"Initializing Azure OpenAI Client for {model_name}, Api Base: {str(api_base)}, Api Key:{_api_key}" ) + + # Extract API key from multiple sources with proper precedence + resolved_api_key = ( + api_key + or litellm_params.get("api_key") + or litellm.api_key + or litellm.azure_key + or get_secret_str("AZURE_OPENAI_API_KEY") + or get_secret_str("AZURE_API_KEY") + ) + azure_client_params = { - "api_key": api_key, + "api_key": resolved_api_key, "azure_endpoint": api_base, "api_version": api_version, "azure_ad_token": azure_ad_token, diff --git a/litellm/llms/azure/files/handler.py b/litellm/llms/azure/files/handler.py index 50c122ccf2c..d7b16d304d4 100644 --- a/litellm/llms/azure/files/handler.py +++ b/litellm/llms/azure/files/handler.py @@ -58,7 +58,7 @@ class AzureOpenAIFilesAPI(BaseAzureLLM): ) if openai_client is None: raise ValueError( - "AzureOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: @@ -106,7 +106,7 @@ class AzureOpenAIFilesAPI(BaseAzureLLM): ) if openai_client is None: raise ValueError( - "AzureOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: @@ -156,7 +156,7 @@ class AzureOpenAIFilesAPI(BaseAzureLLM): ) if openai_client is None: raise ValueError( - "AzureOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: @@ -208,7 +208,7 @@ class AzureOpenAIFilesAPI(BaseAzureLLM): ) if openai_client is None: raise ValueError( - "AzureOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: @@ -262,7 +262,7 @@ class AzureOpenAIFilesAPI(BaseAzureLLM): ) if openai_client is None: raise ValueError( - "AzureOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." + "Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY/AZURE_OPENAI_API_KEY is set in the environment." ) if _is_async is True: