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
In select_azure_base_url_or_endpoint (used to build Azure AI Studio / AI Services URLs), api_base is resolved from the argument, then litellm.api_base, then the AZURE_API_BASE env var. If all are None it raises ValueError, because there is no way to construct the deployment URL without the resource endpoint.
Source
Thrown at litellm/llms/azure/common_utils.py:738
def _get_base_azure_url(
api_base: str | None,
litellm_params: GenericLiteLLMParams | Mapping[str, object] | None,
route: Literal["/openai/responses", "/openai/vector_stores"] | str,
default_api_version: str | Literal["latest", "preview"] | None = None,
) -> str:
"""
Get the base Azure URL for the given route and API version.
Args:
api_base: The base URL of the Azure API.
litellm_params: The litellm parameters.
route: The route to the API.
default_api_version: The default API version to use if no api_version is provided. If 'latest', it will use `openai/v1/...` route.
"""
api_base = api_base or litellm.api_base or get_secret_str("AZURE_API_BASE")
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
litellm_params = litellm_params or {}
api_version: Final = cast(str | None, litellm_params.get("api_version")) or default_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 route not in api_base:
new_url = _add_path_to_api_base(api_base=api_base, ending_path=route)View on GitHub (pinned to 6c2dcb801b)
Solutions
- Pass api_base explicitly: litellm.completion(model="azure_ai/<model>", api_base="https://<resource>.services.ai.azure.com", ...).
- Or export AZURE_API_BASE=https://<resource>.openai.azure.com in the process environment.
- In the proxy/router, add api_base to the model's litellm_params entry.
- Note the message prints the value passed (e.g. api_base=None) — use it to confirm which code path supplied nothing.
Example fix
# before
model_list:
- model_name: gpt4o
litellm_params:
model: azure_ai/gpt-4o
api_key: os.environ/AZURE_API_KEY
# after
model_list:
- model_name: gpt4o
litellm_params:
model: azure_ai/gpt-4o
api_key: os.environ/AZURE_API_KEY
api_base: https://my-resource.services.ai.azure.com Defensive patterns
Strategy: validation
Validate before calling
import litellm, os
def validate_azure_ai_studio(model: str, api_base: str | None) -> None:
resolved = api_base or litellm.api_base or os.getenv("AZURE_API_BASE")
if not resolved:
raise ConfigError(f"api_base required for {model}; set api_base or AZURE_API_BASE") Try / catch
try:
resp = litellm.completion(model="azure_ai/gpt-4o", messages=msgs)
except ValueError as e:
if "api_base is required" in str(e):
raise ConfigError("Add api_base to the model's litellm_params") from e
raise Prevention
- Require api_base in your config schema for azure/azure_ai models (fail at config load).
- Set AZURE_API_BASE as a baseline default in deployment environments.
- Lint proxy YAML: every azure* model entry must have api_base or an env default.
When it happens
Trigger: Calling an azure/ai-studio or inference-endpoint model without api_base in the model metadata, without litellm.api_base set, and without AZURE_API_BASE exported. Also when a router/proxy entry omits api_base for an Azure AI Studio model.
Common situations: Copying an azure model config but dropping the api_base line; environment var lost in container migration (works locally via AZURE_API_BASE, fails in prod); using a model alias whose metadata lacks the endpoint.
Related errors
- AZURE_SENTINEL_DCR_IMMUTABLE_ID is required. Set it as an en
- AZURE_SENTINEL_ENDPOINT is required. Set it as an environmen
- AZURE_SENTINEL_TENANT_ID or AZURE_TENANT_ID is required. Set
- AZURE_SENTINEL_CLIENT_ID or AZURE_CLIENT_ID is required. Set
- AZURE_SENTINEL_CLIENT_SECRET or AZURE_CLIENT_SECRET is requi
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/49518b4d71eb8d52.
Report an issue: GitHub.