Skip to content

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]

chore: merge branch updates and resolve test conflicts

milan7a4567b6b366
diff --cc litellm/llms/azure_ai/common_utils.py
index d09055d7671,9d37d8d1185..daf83120710
--- a/litellm/llms/azure_ai/common_utils.py
+++ b/litellm/llms/azure_ai/common_utils.py
@@@ -5,51 -5,9 +5,53 @@@ import litell
from litellm.llms.base_llm.base_utils import BaseLLMModelInfo, BaseTokenCounter
from litellm.secret_managers.main import get_secret_str
from litellm.types.llms.openai import AllMessageValues
+from litellm.types.router import GenericLiteLLMParams
+
+AzureAIApiKeyHeader = Literal["Authorization", "api-key", "Api-Key", "Ocp-Apim-Subscription-Key"]
+
+
+def get_azure_ai_entra_token(litellm_params: Mapping[str, object] | None = None) -> str | None:
+ """
+ Resolve an Entra ID / OAuth access token for an Azure AI Foundry deployment.
+
+ Accepts the same credential set as the `azure` provider: service principal
+ (`tenant_id` / `client_id` / `client_secret`), a pre-fetched `azure_ad_token`, an OIDC
+ federated token, username/password, or `DefaultAzureCredential` / managed identity.
+ """
+ from litellm.llms.azure.common_utils import get_azure_ad_token
+
+ params = GenericLiteLLMParams.model_validate(litellm_params) if litellm_params else GenericLiteLLMParams()
+
+ return get_azure_ad_token(params)
+
+
+def get_azure_ai_auth_headers(
+ api_key: str | None,
+ litellm_params: Mapping[str, object] | None = None,
+ api_key_header: AzureAIApiKeyHeader = "Authorization",
+ api_key_env_var: str = "AZURE_AI_API_KEY",
+) -> Mapping[str, str]:
+ """
+ Build the auth headers for an Azure AI Foundry route.
+
+ Prefers the API key when one is configured, and otherwise falls back to Entra ID / OAuth,
+ sending the access token as a bearer token.
+ """
+ if api_key:
+ return {api_key_header: f"Bearer {api_key}" if api_key_header == "Authorization" else api_key}
+
+ azure_ad_token = get_azure_ai_entra_token(litellm_params=litellm_params)
+ if azure_ad_token:
+ return {"Authorization": f"Bearer {azure_ad_token}"}
+
+ raise ValueError(
+ f"Missing Azure AI credentials - set an API key (`api_key` or {api_key_env_var}), or Entra ID / OAuth "
+ "credentials (`tenant_id` + `client_id` + `client_secret`, `azure_ad_token`, an OIDC token, or a managed "
+ "identity with `litellm.enable_azure_ad_token_refresh = True`)"
+ )
+ AZURE_MODEL_ROUTER_SELECTED_MODEL_KEY: Final = "azure_model_router_selected_model"
+
class AzureFoundryModelInfo(BaseLLMModelInfo):
"""Model info for Azure AI / Azure Foundry models."""
diff --cc tests/test_litellm/litellm_core_utils/test_litellm_logging.py
index 1cac0cce4ef,a0f7de6b320..25387cc38df
--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py
+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py
@@@ -6,7 -6,8 +6,6 @@@ from unittest.mock import AsyncMock, Ma
import pytest
-sys.path.insert(0, os.path.abspath("../../..")) # Adds the parent directory to the system path
--
import time
import httpx