BerriAI/litellm · error · ValueError
api_key is None. Please set AZURE_AI_API_KEY or dynamically
Error message
api_key is None. Please set AZURE_AI_API_KEY or dynamically via `api_key` param, to make the request.
What it means
Twin guard of the api_base check in the Azure AI image-embeddings handler: after confirming api_base, it requires an api_key for the Authorization: Bearer header and raises ValueError if none, pointing at AZURE_AI_API_KEY or the api_key parameter. Raised client-side before the request is sent.
Source
Thrown at litellm/llms/azure_ai/embed/handler.py:106
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}"},
)
embedding_response: Final = response.json()
embedding_headers: Final = dict(response.headers)
returned_response: Final[EmbeddingResponse] = convert_to_model_response_object(
response_object=embedding_response,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Pass api_key=<foundry key> on the call.
- Or export AZURE_AI_API_KEY in the litellm process environment.
- In proxy config use api_key: os.environ/AZURE_AI_API_KEY so it resolves at startup and fails fast.
- Copy the key from the Foundry project's 'Keys' page — it is the project key, not the Azure subscription key.
Example fix
# before
litellm.embedding(model='azure_ai/img-embed', input=[b64], api_base=base)
# after
litellm.embedding(model='azure_ai/img-embed', input=[b64], api_base=base,
api_key=os.environ['AZURE_AI_API_KEY']) Defensive patterns
Strategy: validation
Validate before calling
import os
def foundry_key() -> str:
key = os.getenv('AZURE_AI_API_KEY')
if not key:
raise RuntimeError('AZURE_AI_API_KEY is required for azure_ai embeddings')
return key Try / catch
try:
litellm.embedding(model='azure_ai/img', input=imgs, api_key=foundry_key())
except ValueError as e:
if 'AZURE_AI_API_KEY' in str(e):
raise ConfigurationError('missing Foundry API key') from e
raise Prevention
- Resolve api_key: os.environ/AZURE_AI_API_KEY in proxy config so absence fails at startup.
- Distinguish AZURE_API_KEY from AZURE_AI_API_KEY in your secret naming.
- Add a pre-flight authenticated call (list models) in health checks to catch bad keys early.
When it happens
Trigger: Azure AI embedding call with api_base set but no api_key and no AZURE_AI_API_KEY env var; key passed as azure_ad_token or under a different name; env var unset in containerized deployments.
Common situations: Secrets moved to a vault and the AZURE_AI_API_KEY injection forgotten in CI; using a Key Vault reference name but the proxy never resolves it; local .env not loaded in the deployed image.
Related errors
- Azure AI API key is required for model {model}. Set AZURE_AI
- Azure OpenAI client is not initialized. Make sure api_key is
- api_key (Azure AD token) is required for Azure Foundry Agent
- api_base is None. Please set AZURE_AI_API_BASE or dynamicall
- embedding_model is required in litellm_params for Azure AI S
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/33faf6f4aad92f53.
Report an issue: GitHub.