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(azure/common_utils.py): add default api version for openai responses api calls
Krrish Dholakiaca642d32e11e
diff --git a/litellm/constants.py b/litellm/constants.pyindex 18f384b4ffb..8d502afaf2c 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -1,6 +1,9 @@import osfrom typing import List, Literal+AZURE_DEFAULT_RESPONSES_API_VERSION = str(+ os.getenv("AZURE_DEFAULT_RESPONSES_API_VERSION", "2025-04-01-preview")+)ROUTER_MAX_FALLBACKS = int(os.getenv("ROUTER_MAX_FALLBACKS", 5))DEFAULT_BATCH_SIZE = int(os.getenv("DEFAULT_BATCH_SIZE", 512))DEFAULT_FLUSH_INTERVAL_SECONDS = int(os.getenv("DEFAULT_FLUSH_INTERVAL_SECONDS", 5))diff --git a/litellm/llms/azure/common_utils.py b/litellm/llms/azure/common_utils.pyindex 94abd2f814e..8581339d883 100644--- a/litellm/llms/azure/common_utils.py+++ b/litellm/llms/azure/common_utils.py@@ -365,14 +365,16 @@ def get_azure_ad_token(azure_ad_token_provider = get_azure_ad_token_provider(azure_scope=scope)except ValueError:verbose_logger.debug("Azure AD Token Provider could not be used.")-+########################################################## If litellm.enable_azure_ad_token_refresh is True and no other token provider is available,# try to get DefaultAzureCredential provider#########################################################if azure_ad_token_provider is None and azure_ad_token is None:- azure_ad_token_provider = BaseAzureLLM._try_get_default_azure_credential_provider(- scope=scope,+ azure_ad_token_provider = (+ BaseAzureLLM._try_get_default_azure_credential_provider(+ scope=scope,+ ))# Execute the token provider to get the token if available@@ -403,27 +405,27 @@ class BaseAzureLLM(BaseOpenAILLM):) -> Optional[Callable[[], str]]:"""Try to get DefaultAzureCredential provider-+Args:scope: Azure scope for the token-+Returns:Token provider callable if DefaultAzureCredential is enabled and available, None otherwise"""from litellm.types.secret_managers.get_azure_ad_token_provider import (AzureCredentialType,)-- verbose_logger.debug(- "Attempting to use DefaultAzureCredential for Azure Auth"- )-++ verbose_logger.debug("Attempting to use DefaultAzureCredential for Azure Auth")+try:azure_ad_token_provider = get_azure_ad_token_provider(azure_scope=scope,azure_credential=AzureCredentialType.DefaultAzureCredential,)- verbose_logger.debug("Successfully obtained Azure AD token provider using DefaultAzureCredential")+ verbose_logger.debug(+ "Successfully obtained Azure AD token provider using DefaultAzureCredential"+ )return azure_ad_token_providerexcept Exception as e:verbose_logger.debug(f"DefaultAzureCredential failed: {str(e)}")@@ -656,17 +658,17 @@ class BaseAzureLLM(BaseOpenAILLM):else:client = AzureOpenAI(**azure_client_params) # type: ignorereturn client-+@staticmethoddef _base_validate_azure_environment(- headers: dict, litellm_params: Optional[GenericLiteLLMParams]+ headers: dict, litellm_params: Optional[GenericLiteLLMParams]) -> dict:litellm_params = litellm_params or GenericLiteLLMParams()-+# If api-key is already in headers, preserve itif "api-key" in headers:return headers-+api_key = (litellm_params.api_keyor litellm.api_key@@ -686,13 +688,15 @@ class BaseAzureLLM(BaseOpenAILLM):headers["Authorization"] = f"Bearer {azure_ad_token}"return headers-+@staticmethoddef _get_base_azure_url(api_base: Optional[str],litellm_params: Optional[Union[GenericLiteLLMParams, Dict[str, Any]]],- route: Literal["/openai/responses", "/openai/vector_stores"]+ route: Literal["/openai/responses", "/openai/vector_stores"],) -> str:+ from litellm.constants import AZURE_DEFAULT_RESPONSES_API_VERSION+api_base = api_base or litellm.api_base or get_secret_str("AZURE_API_BASE")if api_base is None:raise ValueError(@@ -702,35 +706,39 @@ class BaseAzureLLM(BaseOpenAILLM):# Extract api_version or use defaultlitellm_params = litellm_params or {}- api_version = cast(Optional[str], litellm_params.get("api_version"))+ api_version = (+ cast(Optional[str], litellm_params.get("api_version"))+ or AZURE_DEFAULT_RESPONSES_API_VERSION+ )# Create a new dictionary with existing paramsquery_params = dict(original_url.params)# Add api_version if needed- if "api-version" not in query_params and api_version:+ if "api-version" not in query_params:query_params["api-version"] = api_version-+# Add the path to the base URLif route not in api_base:- new_url = _add_path_to_api_base(- api_base=api_base, ending_path=route- )+ new_url = _add_path_to_api_base(api_base=api_base, ending_path=route)else:new_url = api_base-+if BaseAzureLLM._is_azure_v1_api_version(api_version):# ensure the request go to /openai/v1 and not just /openaiif "/openai/v1" not in new_url:parsed_url = httpx.URL(new_url)- new_url = str(parsed_url.copy_with(path=parsed_url.path.replace("/openai", "/openai/v1")))-+ new_url = str(+ parsed_url.copy_with(+ path=parsed_url.path.replace("/openai", "/openai/v1")+ )+ )# Use the new query_params dictionaryfinal_url = httpx.URL(new_url).copy_with(params=query_params)return str(final_url)-+@staticmethoddef _is_azure_v1_api_version(api_version: Optional[str]) -> bool:if api_version is None: