BerriAI/litellm · error · ValueError

Missing Azure API Base - Please set `api_base` or `AZURE_API

Error message

Missing Azure API Base - Please set `api_base` or `AZURE_API_BASE` environment variable. Expected format: https://<resource-name>.services.ai.azure.com/anthropic

What it means

For the Azure Anthropic messages route, LiteLLM constructs https://<resource>.services.ai.azure.com/anthropic/v1/messages from api_base (parameter) or the AZURE_API_BASE environment variable. If both are absent it raises this ValueError, including the expected URL shape, before any network call. Note this route uses AZURE_API_BASE (the Azure OpenAI variable), not AZURE_AI_API_BASE.

Source

Thrown at litellm/llms/azure_ai/anthropic/messages_transformation.py:92

    def get_complete_url(
        self,
        api_base: str | None,
        api_key: str | None,
        model: str,
        optional_params: dict,
        litellm_params: dict,
        stream: bool | None = None,
    ) -> str:
        """
        Get the complete URL for Azure Anthropic /v1/messages endpoint.
        Azure Foundry endpoint format: https://<resource-name>.services.ai.azure.com/anthropic/v1/messages
        """
        from litellm.secret_managers.main import get_secret_str

        api_base = api_base or get_secret_str("AZURE_API_BASE")
        if api_base is None:
            raise ValueError(
                "Missing Azure API Base - Please set `api_base` or `AZURE_API_BASE` environment variable. "
                "Expected format: https://<resource-name>.services.ai.azure.com/anthropic"
            )

        # Ensure the URL ends with /v1/messages
        api_base = api_base.rstrip("/")
        if api_base.endswith("/v1/messages") or api_base.endswith("/anthropic/v1/messages"):
            # Already correct
            pass
        else:
            # Check if /anthropic is already in the path
            if "/anthropic" in api_base:
                # /anthropic exists, ensure we end with /anthropic/v1/messages
                # Extract the base URL up to and including /anthropic
                parts: Final = api_base.split("/anthropic", 1)
                api_base = parts[0] + "/anthropic"
            else:
                # /anthropic not in path, add it

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set api_base on the call or deployment to your Foundry anthropic endpoint: https://<resource>.services.ai.azure.com/anthropic — litellm appends /v1/messages if missing.
  2. Or export AZURE_API_BASE with that value in the environment of the litellm process.
  3. In proxy config, put api_base inside the model's litellm_params block.
  4. Verify with curl that the endpoint answers before retrying through litellm.

Example fix

# before (proxy config missing base)
model_list:
  - model_name: claude
    litellm_params:
      model: azure/claude-3-5-sonnet

# after
model_list:
  - model_name: claude
    litellm_params:
      model: azure/claude-3-5-sonnet
      api_base: https://myfoundry.services.ai.azure.com/anthropic
      api_key: os.environ/AZURE_API_KEY
Defensive patterns

Strategy: validation

Validate before calling

import os

def azure_anthropic_base() -> str:
    base = os.getenv('AZURE_API_BASE')  # note: NOT AZURE_AI_API_BASE
    if not base:
        raise RuntimeError('Set AZURE_API_BASE to https://<resource>.services.ai.azure.com/anthropic')
    return base

Try / catch

try:
    litellm.completion(model='azure/claude-...', api_base=azure_anthropic_base(), ...)
except ValueError as e:
    if 'Missing Azure API Base' in str(e):
        raise ConfigurationError(str(e)) from e
    raise

Prevention

When it happens

Trigger: Calling the azure anthropic messages route with neither api_base on the request/deployment nor AZURE_API_BASE exported; in litellm proxy, forgetting litellm_params.api_base on the model entry; env var present in shell but the proxy runs under systemd/docker without it.

Common situations: Mixed Azure setups where AZURE_AI_API_BASE was set instead of AZURE_API_BASE; moving from direct Anthropic (ANTHROPIC_API_BASE) to Azure-hosted Claude and forgetting the Foundry endpoint; proxy config committed without the base URL because it 'worked locally'.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/11fe801ec6fc566c. Report an issue: GitHub.