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

  1. Pass api_base pointing at your Azure AI Foundry project/agents endpoint
  2. Or export AZURE_AI_API_BASE with that endpoint URL
  3. Double-check the variable name -- AZURE_API_BASE is not read on this route; it must be AZURE_AI_API_BASE
  4. 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

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


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/288cb5b6849acbaf. Report an issue: GitHub.