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): default max_retries to DEFAULT_MAX_RETRIES with regression tests
mateo-berri830ee2d39d84
diff --git a/litellm/llms/azure/common_utils.py b/litellm/llms/azure/common_utils.pyindex f20cc37572b..e6b3eb1f2bb 100644--- a/litellm/llms/azure/common_utils.py+++ b/litellm/llms/azure/common_utils.py@@ -14,6 +14,7 @@ from typing_extensions import ReadOnly, TypedDictimport litellmfrom litellm._logging import verbose_loggerfrom litellm.caching.caching import DualCache+from litellm.constants import DEFAULT_MAX_RETRIESfrom litellm.llms.base_llm.chat.transformation import BaseLLMExceptionfrom litellm.llms.openai.common_utils import BaseOpenAILLMfrom litellm.secret_managers.get_azure_ad_token_provider import (@@ -582,11 +583,8 @@ class BaseAzureLLM(BaseOpenAILLM):if scope is None:scope = "https://cognitiveservices.azure.com/.default"- max_retries = litellm_params.get("max_retries")- if max_retries is None:- from litellm.constants import DEFAULT_MAX_RETRIES-- max_retries = DEFAULT_MAX_RETRIES+ configured_max_retries: Final = litellm_params.get("max_retries")+ max_retries: Final = DEFAULT_MAX_RETRIES if configured_max_retries is None else configured_max_retriestimeout: 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")@@ -646,8 +644,7 @@ class BaseAzureLLM(BaseOpenAILLM):else:azure_client_params["http_client"] = self._get_sync_http_client()- if max_retries is not None:- azure_client_params["max_retries"] = max_retries+ azure_client_params["max_retries"] = max_retriesif timeout is not None:azure_client_params["timeout"] = timeoutdiff --git a/tests/test_litellm/llms/azure/test_azure_common_utils.py b/tests/test_litellm/llms/azure/test_azure_common_utils.pyindex f000abb4c9a..c959c201ccb 100644--- a/tests/test_litellm/llms/azure/test_azure_common_utils.py+++ b/tests/test_litellm/llms/azure/test_azure_common_utils.py@@ -385,6 +385,58 @@ def test_select_azure_base_url_called(setup_mocks):setup_mocks["select_url"].assert_called_once()+def test_initialize_defaults_max_retries_to_litellm_default(setup_mocks):+ result = BaseAzureLLM().initialize_azure_sdk_client(+ litellm_params={},+ api_key="test-api-key",+ api_base="https://test.openai.azure.com",+ model_name="gpt-4",+ api_version="2023-06-01",+ is_async=False,+ )++ assert result["max_retries"] == litellm.constants.DEFAULT_MAX_RETRIES+++ "configured, expected",+ [(0, 0), (5, 5), (None, litellm.constants.DEFAULT_MAX_RETRIES)],+)+def test_initialize_honors_explicit_max_retries(setup_mocks, configured, expected):+ result = BaseAzureLLM().initialize_azure_sdk_client(+ litellm_params={"max_retries": configured},+ api_key="test-api-key",+ api_base="https://test.openai.azure.com",+ model_name="gpt-4",+ api_version="2023-06-01",+ is_async=False,+ )++ assert result["max_retries"] == expected+++def test_default_max_retries_env_var_reaches_azure_sdk_client():+ import subprocess+ import sys++ code = (+ "from litellm.llms.azure.common_utils import BaseAzureLLM\n"+ "client = BaseAzureLLM().get_azure_openai_client("+ "api_key='test-api-key', api_base='https://test.openai.azure.com', api_version='2024-02-01',"+ " client=None, _is_async=True, litellm_params={}, model='gpt-4')\n"+ "print(client.max_retries)"+ )+ completed = subprocess.run(+ [sys.executable, "-c", code],+ env={**os.environ, "DEFAULT_MAX_RETRIES": "0"},+ capture_output=True,+ text=True,+ check=True,+ )++ assert completed.stdout.strip() == "0"++@pytest.mark.parametrize("call_type",[