BerriAI/litellm · error · ValueError
api_base is required for Azure OpenAI LLM provider. Either s
Error message
api_base is required for Azure OpenAI LLM provider. Either set it dynamically or set the AZURE_API_BASE environment variable.
What it means
ValueError raised on the Azure OpenAI chat path when no api_base resolves from the chain: api_base argument > litellm.api_base > AZURE_API_BASE environment variable. Azure requires the per-resource endpoint URL (https://<resource>.openai.azure.com/) to build the request, so an empty value aborts before any HTTP call.
Source
Thrown at litellm/main.py:1393
api_version = ctx.api_version
client: Final = _dispatch_client_azure(ctx)
extra_headers: Final = ctx.extra_headers
headers = ctx.headers
litellm_params: Final = ctx.litellm_params
logger_fn: Final = ctx.logger_fn
logging: Final = ctx.logging
messages: Final = ctx.messages
model: Final = ctx.model
model_response: Final = ctx.model_response
optional_params: Final = ctx.optional_params
timeout: Final = ctx.timeout
api_type: Final = get_secret_str("AZURE_API_TYPE") or "azure"
api_base = api_base or litellm.api_base or get_secret_str("AZURE_API_BASE")
if api_base is None:
raise ValueError(
"api_base is required for Azure OpenAI LLM provider. Either set it dynamically or set the AZURE_API_BASE environment variable."
)
api_version = api_version or litellm.api_version or get_secret_str("AZURE_API_VERSION")
api_key = (
api_key
or litellm.api_key
or litellm.azure_key
or get_secret_str("AZURE_OPENAI_API_KEY")
or get_secret_str("AZURE_API_KEY")
)
azure_ad_token: Final = optional_params.get("extra_body", {}).pop("azure_ad_token", None) or get_secret_str(
"AZURE_AD_TOKEN"
)
azure_ad_token_provider_value: Final = litellm_params.get("azure_ad_token_provider", None)View on GitHub (pinned to 77b7c6c40c)
Solutions
- Export AZURE_API_BASE=https://<your-resource>.openai.azure.com/
- Or pass api_base='https://<resource>.openai.azure.com/' per call / in the Router model_list entry
- Confirm with a quick check: litellm.get_secret_str('AZURE_API_BASE') returns the URL in the failing environment
- If using azure-ad auth, still set api_base -- the endpoint URL is required regardless of auth mode
Example fix
# before resp = litellm.completion(model='azure/my-deploy', messages=m) # ValueError # after import os os.environ['AZURE_API_BASE'] = 'https://my-resource.openai.azure.com/' os.environ['AZURE_API_KEY'] = '...' resp = litellm.completion(model='azure/my-deploy', messages=m)
Defensive patterns
Strategy: validation
Validate before calling
import os
api_base = os.getenv('AZURE_API_BASE') or litellm.api_base
if not api_base:
raise SystemExit('AZURE_API_BASE not set; refusing to call azure models') Type guard
def azure_base_resolved(api_base: str | None) -> bool:
return isinstance(api_base, str) and api_base.startswith('https://') Try / catch
try:
resp = litellm.completion(model='azure/my-deploy', messages=m)
except ValueError as e:
if 'api_base is required for Azure' in str(e):
raise RuntimeError('Azure endpoint unconfigured: set AZURE_API_BASE') from e
raise Prevention
- Put AZURE_API_BASE and AZURE_API_KEY in the same bootstrap as other required env vars and assert them at startup
- For multiple Azure resources, always pass api_base per call or use Router model_list entries instead of the global
- Document that Azure needs the full endpoint URL including https:// and the resource name
- Add env-var presence checks to CI smoke tests for every provider you call
When it happens
Trigger: completion(model='azure/<deployment>') (or azure/ provider routing) with none of: api_base kwarg, litellm.api_base set, AZURE_API_BASE exported.
Common situations: Local script works (env set in shell) but CI/container/lambda lacks AZURE_API_BASE; key rotation scripts set only AZURE_API_KEY and forget the base; deploying with azure-ad token auth but no endpoint URL configured.
Related errors
- No API Base provided for Azure OpenAI LLM provider. Set 'AZU
- Azure AI Agents requests require an api_base. Set `api_base`
- Azure Anthropic requests require an api_base. Set `api_base`
- api_base is required for A2A provider. Either provide api_ba
- 🚨🚨🚨 DISABLING LLM API ENDPOINTS is an Enterprise feature
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/4689dc0cba5e5e42.
Report an issue: GitHub.