{"record":{"id":"3a152e146879f3f0","repo":"BerriAI/litellm","slug":"api-key-azure-ad-token-is-required-for-azure-fou","errorCode":null,"errorMessage":"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'","messagePattern":"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'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/agents/transformation.py","lineNumber":350,"sourceCode":"          - AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET (Service Principal)\n\n        See: https://learn.microsoft.com/en-us/azure/ai-foundry/agents/quickstart\n        \"\"\"\n        from litellm.llms.azure.common_utils import get_azure_ad_token\n        from litellm.llms.azure_ai.agents.handler import azure_ai_agents_handler\n        from litellm.types.router import GenericLiteLLMParams\n\n        # If no api_key is provided, try to get Azure AD token\n        if api_key is None:\n            # Try to get Azure AD token using the existing Azure auth mechanisms\n            # This uses the scope for Azure AI (ai.azure.com) instead of cognitive services\n            # Create a GenericLiteLLMParams with the scope override for Azure Foundry Agents\n            azure_auth_params: Final = dict(litellm_params) if litellm_params else {}\n            azure_auth_params[\"azure_scope\"] = \"https://ai.azure.com/.default\"\n            api_key = get_azure_ad_token(GenericLiteLLMParams(**azure_auth_params))\n\n        if api_key is None:\n            raise ValueError(\n                \"api_key (Azure AD token) is required for Azure Foundry Agents. \"\n                \"Either pass api_key directly, or set AZURE_TENANT_ID, AZURE_CLIENT_ID, \"\n                \"and AZURE_CLIENT_SECRET environment variables for Service Principal auth. \"\n                \"Manual token: az account get-access-token --resource 'https://ai.azure.com'\"\n            )\n        if acompletion:\n            if stream:\n                # Native async streaming via SSE - return the async generator directly\n                return azure_ai_agents_handler.acompletion_stream(\n                    model=model,\n                    messages=messages,\n                    api_base=api_base,\n                    api_key=api_key,\n                    logging_obj=logging_obj,\n                    optional_params=optional_params,\n                    litellm_params=litellm_params,\n                    timeout=timeout,\n                    headers=headers,","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/azure_ai/agents/transformation.py#L332-L368","documentation":"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.","triggerScenarios":"Thrown at litellm/llms/azure_ai/agents/transformation.py:350 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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'."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}