fix(azure): respect DEFAULT_MAX_RETRIES in initialize_azure_sdk_client

When litellm_params does not include max_retries (the common case for
deployments configured without explicit retry settings),
initialize_azure_sdk_client() previously passed None through the
'if max_retries is not None' guard, resulting in AsyncAzureOpenAI being
created without a max_retries argument. The OpenAI SDK then uses its
own hardcoded default of 2, ignoring the DEFAULT_MAX_RETRIES env var.

Fix: fall back to litellm.constants.DEFAULT_MAX_RETRIES when
litellm_params has no max_retries. This ensures the SDK client
respects the configured retry count.

Steps to reproduce:
  1. Set env var DEFAULT_MAX_RETRIES=0
  2. Configure a deployment without explicit max_retries in litellm_params
  3. Make a request that triggers a timeout
  4. Observe: SDK retries (x-stainless-retry-count=1) despite env var=0

Related: https://github.com/BerriAI/litellm/issues/5124
This commit is contained in:
Praveena 2026-08-04 16:33:28 +05:30 committed by mateo-berri
parent 9315f5dd5e
commit 5e7cb89806

View file

@ -582,7 +582,11 @@ class BaseAzureLLM(BaseOpenAILLM):
if scope is None:
scope = "https://cognitiveservices.azure.com/.default"
max_retries: Final = litellm_params.get("max_retries")
max_retries = litellm_params.get("max_retries")
if max_retries is None:
from litellm.constants import DEFAULT_MAX_RETRIES
max_retries = DEFAULT_MAX_RETRIES
timeout: Final = litellm_params.get("timeout")
if not api_key and azure_ad_token_provider is None and tenant_id and client_id and client_secret:
verbose_logger.debug("Using Azure AD Token Provider from Entra ID for Azure Auth")