BerriAI/litellm · error · ValueError
api_base is required for Azure AI Studio. Please set the api
Error message
api_base is required for Azure AI Studio. Please set the api_base parameter. Passed `api_base={api_base}` What it means
The Azure AI Studio (Foundry) chat transformation requires a base URL to build https://<resource>.services.ai.azure.com/models/chat/completions?api-version=.... If api_base is None it raises ValueError, echoing the (None) value you passed. Foundry has no inferable default endpoint, so this is thrown client-side before any request.
Source
Thrown at litellm/llms/azure_ai/chat/transformation.py:120
) -> str:
"""
Constructs a complete URL for the API request.
Args:
- api_base: Base URL, e.g.,
"https://litellm8397336933.services.ai.azure.com"
OR
"https://litellm8397336933.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview"
- model: Model name.
- optional_params: Additional query parameters, including "api_version".
- stream: If streaming is required (optional).
Returns:
- A complete URL string, e.g.,
"https://litellm8397336933.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview"
"""
if api_base is None:
raise ValueError(
f"api_base is required for Azure AI Studio. Please set the api_base parameter. Passed `api_base={api_base}`"
)
original_url: Final = httpx.URL(api_base)
# Extract api_version or use default
api_version: Final = cast(str | None, litellm_params.get("api_version"))
# Create a new dictionary with existing params
query_params: Final = dict(original_url.params)
# Add api_version if needed
if "api-version" not in query_params and api_version:
query_params["api-version"] = api_version
# Add the path to the base URL
if "services.ai.azure.com" in api_base:
new_url = _add_path_to_api_base(api_base=api_base, ending_path="/models/chat/completions")
else:View on GitHub (pinned to 6c2dcb801b)
Solutions
- Pass api_base: https://<resource>.services.ai.azure.com (optionally with /models/chat/completions?api-version=... which litellm normalizes).
- Or set AZURE_AI_API_BASE in the process environment.
- If you actually have an Azure OpenAI resource (not Foundry), switch the model prefix from azure_ai/ to azure/ and use AZURE_API_BASE.
- In proxy config, add api_base under the deployment's litellm_params.
Example fix
# before
litellm.completion(model='azure_ai/gpt-4o', api_key=k, messages=m)
# after
litellm.completion(
model='azure_ai/gpt-4o', api_key=k, messages=m,
api_base='https://litellm8397336933.services.ai.azure.com',
) Defensive patterns
Strategy: validation
Validate before calling
import os
def foundry_chat_base(api_base: str | None) -> str:
base = api_base or os.getenv('AZURE_AI_API_BASE')
if base is None:
raise RuntimeError('azure_ai chat requires api_base or AZURE_AI_API_BASE')
return base Try / catch
try:
litellm.completion(model='azure_ai/gpt-4o', api_base=foundry_chat_base(None), ...)
except ValueError as e:
if 'api_base is required for Azure AI Studio' in str(e):
raise ConfigurationError(str(e)) from e
raise Prevention
- Choose the prefix deliberately: azure/ uses AZURE_API_BASE, azure_ai/ needs AZURE_AI_API_BASE.
- Validate provider env vars at process start with a single settings loader.
- In proxy configs, always set api_base on foundry deployments — never depend on ambient env.
When it happens
Trigger: completion(model='azure_ai/<model>', ...) without api_base and without AZURE_AI_API_BASE env var; supplying only deployment name and api_key (the pattern for plain Azure OpenAI, which resolves via AZURE_API_BASE); passing api_base=None explicitly.
Common situations: Copy-pasted Azure OpenAI config used against an azure_ai model; env var set after process start; proxy deployment entry missing api_base; confusion between the azure/ and azure_ai/ provider prefixes.
Related errors
- api_base is required for Azure AVA TTS. Format: https://{reg
- api_base is required for Azure AI Agents. Set it via AZURE_A
- Missing Azure API Base - Please set `api_base` or `AZURE_API
- api_base is required for Azure AI Studio. Please set the api
- Azure api base not found
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/50e838402adc3a22.
Report an issue: GitHub.