BerriAI/litellm · error · ValueError
Azure AI API Base is required. api_base=None. Set in call or
Error message
Azure AI API Base is required. api_base=None. Set in call or via `AZURE_AI_API_BASE` env var.
What it means
Azure AI rerank reuses the Cohere rerank spec but targets your Azure AI resource, so it needs the resource endpoint. get_complete_url raises this when api_base is None — no fallback to a default host exists. Set it per call or via AZURE_AI_API_BASE.
Source
Thrown at litellm/llms/azure_ai/rerank/transformation.py:29
from litellm.llms.cohere.rerank.transformation import CohereRerankConfig
from litellm.secret_managers.main import get_secret_str
from litellm.types.utils import RerankResponse
from litellm.utils import _add_path_to_api_base
class AzureAIRerankConfig(CohereRerankConfig):
"""
Azure AI Rerank - Follows the same Spec as Cohere Rerank
"""
def get_complete_url(
self,
api_base: str | None,
model: str,
optional_params: dict | None = None,
) -> str:
if api_base is None:
raise ValueError(
"Azure AI API Base is required. api_base=None. Set in call or via `AZURE_AI_API_BASE` env var."
)
original_url: Final = httpx.URL(api_base)
if not original_url.is_absolute_url:
raise ValueError(
"Azure AI API Base must be an absolute URL including scheme (e.g. "
"'https://<resource>.services.ai.azure.com'). "
f"Got api_base={api_base!r}."
)
normalized_path: Final = original_url.path.rstrip("/")
# Allow callers to pass either full v1/v2 rerank endpoints:
# - https://<resource>.services.ai.azure.com/v1/rerank
# - https://<resource>.services.ai.azure.com/providers/cohere/v2/rerank
if normalized_path.endswith("/v1/rerank") or normalized_path.endswith("/v2/rerank"):
return str(original_url.copy_with(path=normalized_path or "/"))
# If callers pass just the version path (e.g. ".../v2" or ".../providers/cohere/v2"), append "/rerank"View on GitHub (pinned to 6c2dcb801b)
Solutions
- export AZURE_AI_API_BASE=https://<resource>.services.ai.azure.com
- Or pass api_base='https://<resource>.services.ai.azure.com' to litellm.rerank(...)
- In the proxy, set litellm_params.api_base for the azure_ai rerank model and reload config
Example fix
# before litellm.rerank(model='azure_ai/cohere-rerank-v3.5', query='hello', documents=['a','b']) # after litellm.rerank(model='azure_ai/cohere-rerank-v3.5', query='hello', documents=['a','b'], api_base='https://my-resource.services.ai.azure.com', api_key=os.environ['AZURE_AI_API_KEY'])
Defensive patterns
Strategy: validation
Validate before calling
api_base = os.environ.get('AZURE_AI_API_BASE')
assert api_base, 'AZURE_AI_API_BASE must be set for azure_ai rerank' Prevention
- Set AZURE_AI_API_BASE and AZURE_AI_API_KEY together in deployment env
- Wrap azure_ai rerank calls in a thin client function that injects api_base
When it happens
Trigger: Calling litellm.rerank(model='azure_ai/<cohere-rerank-model>', query=..., documents=[...]) without api_base in the call, router model_info, or the AZURE_AI_API_BASE environment variable.
Common situations: Switching from cohere/rerank-v3.5 to azure_ai/... and forgetting the endpoint is not derivable from the model name; proxy config.yaml model entry missing api_base; local .env not loaded in the deployment.
Related errors
- Missing Azure AI API Base - Set AZURE_AI_API_BASE environmen
- Azure AI API Base must be an absolute URL including scheme (
- Azure AI API key is required. Please set 'AZURE_AI_API_KEY'
- AZURE_SENTINEL_DCR_IMMUTABLE_ID is required. Set it as an en
- AZURE_SENTINEL_ENDPOINT is required. Set it as an environmen
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/aafb658d5996e7e3.
Report an issue: GitHub.