BerriAI/litellm · error · ValueError
Azure AI Agents requests require an api_base. Set `api_base`
Error message
Azure AI Agents requests require an api_base. Set `api_base` or the AZURE_AI_API_BASE env var.
What it means
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.
Source
Thrown at litellm/main.py:1545
messages = ctx.messages
model: Final = ctx.model
model_response: Final = ctx.model_response
optional_params: Final = ctx.optional_params
shared_session: Final = ctx.shared_session
stream: Final = ctx.stream
timeout: Final = ctx.timeout
from litellm.llms.azure_ai.common_utils import AzureFoundryModelInfo
azure_ai_route: Final = AzureFoundryModelInfo.get_azure_ai_route(model)
# Check if this is an agents route - model format: azure_ai/agents/<agent_id>
if azure_ai_route == "agents":
from litellm.llms.azure_ai.agents import AzureAIAgentsConfig
api_base = AzureFoundryModelInfo.get_api_base(api_base)
if api_base is None:
raise ValueError(
"Azure AI Agents requests require an api_base. Set `api_base` or the AZURE_AI_API_BASE env var."
)
api_key = AzureFoundryModelInfo.get_api_key(api_key)
response = AzureAIAgentsConfig.completion(
model=model,
messages=messages,
api_base=api_base,
api_key=api_key,
model_response=model_response,
logging_obj=logging,
optional_params=optional_params,
litellm_params=litellm_params,
timeout=timeout,
acompletion=acompletion,
stream=stream,
headers=headers or litellm.headers,
)View on GitHub (pinned to 77b7c6c40c)
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
Example fix
# before resp = litellm.completion(model='azure_ai/agents/asst_123', messages=m) # ValueError # after import os os.environ['AZURE_AI_API_BASE'] = 'https://<resource>.services.ai.azure.com/api/projects/<project>' resp = litellm.completion(model='azure_ai/agents/asst_123', messages=m)
Defensive patterns
Strategy: validation
Validate before calling
import os
if model.startswith('azure_ai/agents/') and not (api_base or os.getenv('AZURE_AI_API_BASE')):
raise SystemExit('azure_ai agents need api_base or AZURE_AI_API_BASE') Type guard
def azure_ai_agents_ready(model: str, api_base: str | None) -> bool:
return not model.startswith('azure_ai/agents/') or bool(api_base or os.getenv('AZURE_AI_API_BASE')) Try / catch
try:
resp = litellm.completion(model='azure_ai/agents/asst_123', messages=m)
except ValueError as e:
if 'Azure AI Agents requests require an api_base' in str(e):
raise RuntimeError('Set AZURE_AI_API_BASE (not AZURE_API_BASE) for agents routes') from e
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Azure Anthropic requests require an api_base. Set `api_base`
- api_base is required for A2A provider. Either provide api_ba
- api_base is required for Azure OpenAI LLM provider. Either s
- No API Base provided for Azure OpenAI LLM provider. Set 'AZU
- 🚨🚨🚨 DISABLING LLM API ENDPOINTS is an Enterprise feature
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/288cb5b6849acbaf.
Report an issue: GitHub.