BerriAI/litellm · error · ValueError
Missing Azure AI API Base - Set AZURE_AI_API_BASE environmen
Error message
Missing Azure AI API Base - Set AZURE_AI_API_BASE environment variable or pass api_base parameter
What it means
Thrown by the Azure AI OCR config's validate_environment when building request headers: no API base URL could be resolved. LiteLLM needs the Azure AI services endpoint (e.g. https://<resource>.services.ai.azure.com) to know where to send the OCR request, and it looked both in the explicit api_base parameter and the AZURE_AI_API_BASE environment variable before giving up.
Source
Thrown at litellm/llms/azure_ai/ocr/transformation.py:66
Validate environment and return headers for Azure AI OCR.
Azure AI uses Bearer token authentication with AZURE_AI_API_KEY.
"""
# Get API key from environment if not provided
if api_key is None:
api_key = get_secret_str(AZURE_AI_OCR_API_KEY_ENV_VAR)
if api_key is None:
raise ValueError(
"Missing Azure AI API Key - A call is being made to Azure AI but no key is set either in the environment variables or via params"
)
# Validate API base is provided
if api_base is None:
api_base = get_secret_str("AZURE_AI_API_BASE")
if api_base is None:
raise ValueError(
"Missing Azure AI API Base - Set AZURE_AI_API_BASE environment variable or pass api_base parameter"
)
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
**headers,
}
return headers
def get_complete_url(
self,
api_base: str | None,
model: str,
optional_params: dict,
litellm_params: dict | None = None,
**kwargs,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Set the environment variable: export AZURE_AI_API_BASE=https://<your-resource>.services.ai.azure.com
- Or pass api_base explicitly: litellm.ocr(model='azure_ai/mistral-ocr', document=..., api_base='https://<resource>.services.ai.azure.com', api_key=...)
- If using LiteLLM proxy, add api_base (and api_key) to the model's litellm_params in config.yaml and restart
Example fix
# before
litellm.ocr(model='azure_ai/mistral-ocr', document={'type':'document_url','document_url':url}, api_key=os.environ['AZURE_AI_API_KEY'])
# after
litellm.ocr(model='azure_ai/mistral-ocr', document={'type':'document_url','document_url':url}, api_key=os.environ['AZURE_AI_API_KEY'], api_base='https://my-resource.services.ai.azure.com') Defensive patterns
Strategy: validation
Validate before calling
import os
api_base = os.environ.get('AZURE_AI_API_BASE')
if not api_base:
raise SystemExit('Configure AZURE_AI_API_BASE before running OCR jobs') Try / catch
try:
litellm.ocr(model='azure_ai/mistral-ocr', document=doc)
except ValueError as e:
if 'Missing Azure AI API Base' in str(e):
raise ConfigurationError('Azure AI endpoint not set') from e
raise Prevention
- Centralize Azure AI credentials in one config module that asserts AZURE_AI_API_BASE and AZURE_AI_API_KEY at startup
- Add config smoke tests that call a cheap Azure AI endpoint in CI
When it happens
Trigger: Calling litellm.ocr(...) with an azure_ai/mistral-ocr model while neither api_base is passed (or router model_info entry) nor AZURE_AI_API_BASE is set in the environment. The header builder resolves the API key first, so a missing key fails earlier; this fires only when the key exists but the base URL does not.
Common situations: Copying an OCR example that hardcodes only the API key; deploying to a new environment (container/CI) where AZURE_AI_API_BASE was not exported; using the proxy where the model entry in config.yaml lacks api_base.
Related errors
- Azure AI API Base is required. api_base=None. Set in call or
- 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
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/8459c79d173e7fb7.
Report an issue: GitHub.