BerriAI/litellm · error · ValueError
Azure Anthropic requests require an api_base. Set `api_base`
Error message
Azure Anthropic requests require an api_base. Set `api_base` or the AZURE_AI_API_BASE env var.
What it means
ValueError raised when a Claude model under the azure_ai provider routes to the Azure Anthropic handler (the code even normalizes the URL toward .../anthropic and /v1/messages) but AzureFoundryModelInfo.get_api_base finds no endpoint via api_base, litellm.api_base, or AZURE_AI_API_BASE. Claude-on-Foundry deployments are addressed by their deployment URL, so litellm aborts before calling.
Source
Thrown at litellm/main.py:1570
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,
)
# Check if this is a Claude model - route to Azure Anthropic handler
elif "claude" in model.lower():
# Use Azure Anthropic handler for Claude models
api_base = AzureFoundryModelInfo.get_api_base(api_base)
if api_base is None:
raise ValueError(
"Azure Anthropic requests require an api_base. Set `api_base` or the AZURE_AI_API_BASE env var."
)
api_key = AzureFoundryModelInfo.get_api_key(api_key)
# Ensure the URL ends with /v1/messages for Anthropic
if api_base:
api_base = api_base.rstrip("/")
if not api_base.endswith("/v1/messages"):
if "/anthropic" in api_base:
parts: Final = api_base.split("/anthropic", 1)
api_base = parts[0] + "/anthropic"
else:
api_base = api_base + "/anthropic"
api_base = api_base + "/v1/messages"
response = azure_anthropic_chat_completions.completion(
model=model,
messages=messages,View on GitHub (pinned to 77b7c6c40c)
Solutions
- Pass api_base set to your Foundry Claude deployment URL (the code will append /v1/messages as needed)
- Or export AZURE_AI_API_BASE with that URL
- Verify the URL contains the anthropic/deployment segment you expect; the handler splits on '/anthropic' when normalizing
- Confirm auth (api_key/AZURE_AI_API_KEY) is also set once the base is fixed
Example fix
# before resp = litellm.completion(model='azure_ai/claude-3-5-sonnet', messages=m) # ValueError # after import os os.environ['AZURE_AI_API_BASE'] = 'https://<resource>.services.ai.azure.com/api/projects/<proj>/deployments/claude-3-5-sonnet' os.environ['AZURE_AI_API_KEY'] = '...' resp = litellm.completion(model='azure_ai/claude-3-5-sonnet', messages=m)
Defensive patterns
Strategy: validation
Validate before calling
import os
needs_foundry = model.startswith('azure_ai/') and 'claude' in model.lower()
if needs_foundry and not (api_base or os.getenv('AZURE_AI_API_BASE')):
raise SystemExit('Claude on azure_ai needs api_base or AZURE_AI_API_BASE') Type guard
def azure_anthropic_ready(model: str, api_base: str | None) -> bool:
return 'claude' not in model.lower() or bool(api_base or os.getenv('AZURE_AI_API_BASE')) Try / catch
try:
resp = litellm.completion(model='azure_ai/claude-3-5-sonnet', messages=m)
except ValueError as e:
if 'Azure Anthropic requests require an api_base' in str(e):
raise RuntimeError('Configure the Foundry Claude deployment URL via api_base/AZURE_AI_API_BASE') from e
raise Prevention
- Keep the Foundry Claude deployment URL in version-controlled config, not shell history
- Verify the URL reaches the anthropic deployment; the handler appends /v1/messages itself
- When migrating providers, audit env var names -- azure_ai uses AZURE_AI_* not AZURE_*
- Add a startup check for every azure_ai model string in your config
When it happens
Trigger: completion(model='azure_ai/<claude-deployment>', ...) with none of api_base kwarg / litellm.api_base / AZURE_AI_API_BASE set; or only AZURE_API_BASE exported, which this path does not consult.
Common situations: Migrating from Azure OpenAI to a Claude model on Azure AI Foundry and reusing the old env setup; the deployment URL (which ends in /deployments/<name>) never configured in the new environment.
Related errors
- Azure AI Agents requests require an api_base. Set `api_base`
- api_base is required for Azure OpenAI LLM provider. Either s
- api_base is required for A2A provider. Either provide api_ba
- 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/2a95e3d5b2048e99.
Report an issue: GitHub.