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: