BerriAI/litellm · error · ValueError
api_key (Azure AD token) is required for Azure Foundry…
Error message
api_key (Azure AD token) is required for Azure Foundry Agents. Either pass api_key directly, or set AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET environment variables for Service Principal auth. Manual token: az account get-access-token --resource 'https://ai.azure.com'
What it means
Error "api_key (Azure AD token) is required for Azure Foundry Agents. Either pass api_key directly, or set AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET environment variables for Service Principal auth. Manual token: az account get-access-token --resource 'https://ai.azure.com'" thrown in BerriAI/litellm.
Solutions
- Pass api_key (Azure AD token), or set AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET for service principal auth.
- Get a token manually: az account get-access-token --resource 'https://ai.azure.com'.
When it happens
Trigger: Thrown at litellm/llms/azure_ai/agents/transformation.py:350 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/3a152e146879f3f0.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/azure_ai/agents/transformation.py:350
- AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET (Service Principal)
See: https://learn.microsoft.com/en-us/azure/ai-foundry/agents/quickstart
"""
from litellm.llms.azure.common_utils import get_azure_ad_token
from litellm.llms.azure_ai.agents.handler import azure_ai_agents_handler
from litellm.types.router import GenericLiteLLMParams
# If no api_key is provided, try to get Azure AD token
if api_key is None:
# Try to get Azure AD token using the existing Azure auth mechanisms
# This uses the scope for Azure AI (ai.azure.com) instead of cognitive services
# Create a GenericLiteLLMParams with the scope override for Azure Foundry Agents
azure_auth_params: Final = dict(litellm_params) if litellm_params else {}
azure_auth_params["azure_scope"] = "https://ai.azure.com/.default"
api_key = get_azure_ad_token(GenericLiteLLMParams(**azure_auth_params))
if api_key is None:
raise ValueError(
"api_key (Azure AD token) is required for Azure Foundry Agents. "
"Either pass api_key directly, or set AZURE_TENANT_ID, AZURE_CLIENT_ID, "
"and AZURE_CLIENT_SECRET environment variables for Service Principal auth. "
"Manual token: az account get-access-token --resource 'https://ai.azure.com'"
)
if acompletion:
if stream:
# Native async streaming via SSE - return the async generator directly
return azure_ai_agents_handler.acompletion_stream(
model=model,
messages=messages,
api_base=api_base,
api_key=api_key,
logging_obj=logging_obj,
optional_params=optional_params,
litellm_params=litellm_params,
timeout=timeout,
headers=headers,View on GitHub (pinned to 77b7c6c40c)