BerriAI/litellm · error · ValueError
api_base is None. Please set AZURE_AI_API_BASE or dynamicall
Error message
api_base is None. Please set AZURE_AI_API_BASE or dynamically via `api_base` param, to make the request.
What it means
The Azure AI image-embeddings handler POSTs to {api_base}/images/embeddings. Without api_base the URL cannot be built, so it raises ValueError pointing you to the AZURE_AI_API_BASE env var or the api_base parameter. Raised in the sync and async embedding paths before any HTTP traffic.
Source
Thrown at litellm/llms/azure_ai/embed/handler.py:102
stream=False,
_response_headers=embedding_headers,
)
return returned_response
def image_embedding(
self,
model: str,
data: ImageEmbeddingRequest,
timeout: float,
logging_obj,
model_response: EmbeddingResponse,
optional_params: dict,
api_key: str | None,
api_base: str | None,
client: HTTPHandler | AsyncHTTPHandler | None = None,
):
if api_base is None:
raise ValueError(
"api_base is None. Please set AZURE_AI_API_BASE or dynamically via `api_base` param, to make the request."
)
if api_key is None:
raise ValueError(
"api_key is None. Please set AZURE_AI_API_KEY or dynamically via `api_key` param, to make the request."
)
if client is None or not isinstance(client, HTTPHandler):
client = HTTPHandler(timeout=timeout, concurrent_limit=1)
url: Final = f"{api_base}/images/embeddings"
response: Final = client.post(
url=url,
json=data,
headers={"Authorization": f"Bearer {api_key}"},
)
View on GitHub (pinned to 6c2dcb801b)
Solutions
- Pass api_base (your Foundry project endpoint, e.g. https://<resource>.services.ai.azure.com) to the embedding call.
- Or export AZURE_AI_API_BASE in the runtime environment.
- In proxy config, set api_base in the image-embedding deployment's litellm_params.
- Confirm the resource actually exposes /images/embeddings (a Cohlete image-embedding deployment) with curl before retrying.
Example fix
# before
litellm.embedding(model='azure_ai/<image-embed-model>', input=[img_b64])
# after
litellm.embedding(
model='azure_ai/<image-embed-model>',
input=[img_b64],
api_base='https://myres.services.ai.azure.com',
api_key=AZURE_AI_KEY,
) Defensive patterns
Strategy: validation
Validate before calling
import os
def image_embed_base() -> str:
base = os.getenv('AZURE_AI_API_BASE')
if not base:
raise RuntimeError('image embeddings need AZURE_AI_API_BASE or api_base param')
return base Try / catch
try:
litellm.embedding(model='azure_ai/img', input=imgs, api_base=image_embed_base())
except ValueError as e:
if 'AZURE_AI_API_BASE' in str(e):
raise ConfigurationError(str(e)) from e
raise Prevention
- Extend your startup config check to image-embedding routes, not just chat.
- Keep the Foundry endpoint in a shared secret/config store so all Azure AI calls agree.
- Unit-test config resolution so missing env fails in CI, not in production.
When it happens
Trigger: litellm.embedding() on an azure_ai image-embedding model without api_base on the call and without AZURE_AI_API_BASE in the environment; config built for text embeddings (which may resolve a default) reused for the image route.
Common situations: Adding image embedding support to an existing text-embedding service and forgetting the Foundry endpoint; env var not propagated to k8s pod; mixing up AZURE_API_BASE vs AZURE_AI_API_BASE.
Related errors
- api_base is required for Azure AI Studio. Please set the api
- Azure api base not found
- api_base is required for Azure OpenAI calls
- api_base is required for Azure WebSocket
- api_base is required for Azure AVA TTS. Format: https://{reg
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/aaae8cd22eb0dedf.
Report an issue: GitHub.