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: add default credential for azure (#7095) (#7891)
Krish Dholakiab81072d90c18
diff --git a/litellm/secret_managers/get_azure_ad_token_provider.py b/litellm/secret_managers/get_azure_ad_token_provider.pyindex 82e725ee871..f8741115ca8 100644--- a/litellm/secret_managers/get_azure_ad_token_provider.py+++ b/litellm/secret_managers/get_azure_ad_token_provider.py@@ -1,5 +1,7 @@import os-from typing import Callable+from typing import Callable, Union++from litellm._logging import verbose_loggerdef get_azure_ad_token_provider() -> Callable[[], str]:@@ -14,18 +16,29 @@ def get_azure_ad_token_provider() -> Callable[[], str]:Returns:Callable that returns a temporary authentication token."""- from azure.identity import ClientSecretCredential, get_bearer_token_provider+ from azure.identity import (+ ClientSecretCredential,+ DefaultAzureCredential,+ get_bearer_token_provider,+ )try:- credential = ClientSecretCredential(- client_id=os.environ["AZURE_CLIENT_ID"],- client_secret=os.environ["AZURE_CLIENT_SECRET"],- tenant_id=os.environ["AZURE_TENANT_ID"],+ credential: Union[ClientSecretCredential, DefaultAzureCredential] = (+ ClientSecretCredential(+ client_id=os.environ["AZURE_CLIENT_ID"],+ client_secret=os.environ["AZURE_CLIENT_SECRET"],+ tenant_id=os.environ["AZURE_TENANT_ID"],+ ))except KeyError as e:- raise ValueError(- "Missing environment variable required by Azure AD workflow."- ) from e+ verbose_logger.exception(+ "Missing environment variable required by Azure AD workflow. "+ "DefaultAzureCredential will be used"+ " {}".format(str(e))+ )+ credential = DefaultAzureCredential()+ except Exception:+ raisereturn get_bearer_token_provider(credential,diff --git a/tests/local_testing/test_router_client_init.py b/tests/local_testing/test_router_client_init.pyindex bdfd71972e9..0249358e91e 100644--- a/tests/local_testing/test_router_client_init.py+++ b/tests/local_testing/test_router_client_init.py@@ -84,6 +84,9 @@ async def test_router_init():)+ reason="This test is not relevant to the current codebase. The default Azure AD workflow is used."+)@patch("litellm.secret_managers.get_azure_ad_token_provider.os")def test_router_init_with_neither_api_key_nor_azure_service_principal_with_secret(mocked_os_lib: MagicMock,