{"record":{"id":"288cb5b6849acbaf","repo":"BerriAI/litellm","slug":"azure-ai-agents-requests-require-an-api-base-set","errorCode":null,"errorMessage":"Azure AI Agents requests require an api_base. Set `api_base` or the AZURE_AI_API_BASE env var.","messagePattern":"Azure AI Agents requests require an api_base\\. Set `api_base` or the AZURE_AI_API_BASE env var\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/main.py","lineNumber":1545,"sourceCode":"    messages = ctx.messages\n    model: Final = ctx.model\n    model_response: Final = ctx.model_response\n    optional_params: Final = ctx.optional_params\n    shared_session: Final = ctx.shared_session\n    stream: Final = ctx.stream\n    timeout: Final = ctx.timeout\n\n    from litellm.llms.azure_ai.common_utils import AzureFoundryModelInfo\n\n    azure_ai_route: Final = AzureFoundryModelInfo.get_azure_ai_route(model)\n\n    # Check if this is an agents route - model format: azure_ai/agents/<agent_id>\n    if azure_ai_route == \"agents\":\n        from litellm.llms.azure_ai.agents import AzureAIAgentsConfig\n\n        api_base = AzureFoundryModelInfo.get_api_base(api_base)\n        if api_base is None:\n            raise ValueError(\n                \"Azure AI Agents requests require an api_base. Set `api_base` or the AZURE_AI_API_BASE env var.\"\n            )\n        api_key = AzureFoundryModelInfo.get_api_key(api_key)\n\n        response = AzureAIAgentsConfig.completion(\n            model=model,\n            messages=messages,\n            api_base=api_base,\n            api_key=api_key,\n            model_response=model_response,\n            logging_obj=logging,\n            optional_params=optional_params,\n            litellm_params=litellm_params,\n            timeout=timeout,\n            acompletion=acompletion,\n            stream=stream,\n            headers=headers or litellm.headers,\n        )","sourceCodeStart":1527,"sourceCodeEnd":1563,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/main.py#L1527-L1563","documentation":"ValueError raised when a model in the azure_ai/agents/<agent_id> format routes to the Azure AI Agents handler but AzureFoundryModelInfo.get_api_base cannot resolve an endpoint from the api_base argument, litellm.api_base, or AZURE_AI_API_BASE. The Agents API needs the Foundry project endpoint URL to address the agent.","triggerScenarios":"completion(model='azure_ai/agents/<agent-id>', ...) with no api_base kwarg, no litellm.api_base, and no AZURE_AI_API_BASE exported in the environment.","commonSituations":"Trying the new azure_ai agents route with only AZURE_API_BASE set (wrong variable name); copying an example that assumes the env var is preconfigured; running in CI where Foundry env vars were never added.","solutions":["Pass api_base pointing at your Azure AI Foundry project/agents endpoint","Or export AZURE_AI_API_BASE with that endpoint URL","Double-check the variable name -- AZURE_API_BASE is not read on this route; it must be AZURE_AI_API_BASE","Verify the model string is azure_ai/agents/<agent_id> so routing and endpoint resolution line up"],"exampleFix":"# before\nresp = litellm.completion(model='azure_ai/agents/asst_123', messages=m)  # ValueError\n\n# after\nimport os\nos.environ['AZURE_AI_API_BASE'] = 'https://<resource>.services.ai.azure.com/api/projects/<project>'\nresp = litellm.completion(model='azure_ai/agents/asst_123', messages=m)","handlingStrategy":"validation","validationCode":"import os\nif model.startswith('azure_ai/agents/') and not (api_base or os.getenv('AZURE_AI_API_BASE')):\n    raise SystemExit('azure_ai agents need api_base or AZURE_AI_API_BASE')","typeGuard":"def azure_ai_agents_ready(model: str, api_base: str | None) -> bool:\n    return not model.startswith('azure_ai/agents/') or bool(api_base or os.getenv('AZURE_AI_API_BASE'))","tryCatchPattern":"try:\n    resp = litellm.completion(model='azure_ai/agents/asst_123', messages=m)\nexcept ValueError as e:\n    if 'Azure AI Agents requests require an api_base' in str(e):\n        raise RuntimeError('Set AZURE_AI_API_BASE (not AZURE_API_BASE) for agents routes') from e\n    raise","preventionTips":["Remember azure_ai routes read AZURE_AI_API_BASE -- a different variable than AZURE_API_BASE","Store the Foundry project endpoint URL next to the agent id in config so they never drift apart","Smoke-test azure_ai/agents model strings at deploy time with a trivial completion","Keep a mapping doc of provider -> required env vars for your deployment"],"tags":["azure-ai","agents","api-base","env-var","litellm"],"backgroundTag":"missing-api-base","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}