{"record":{"id":"33faf6f4aad92f53","repo":"BerriAI/litellm","slug":"api-key-is-none-please-set-azure-ai-api-key-or-dy","errorCode":null,"errorMessage":"api_key is None. Please set AZURE_AI_API_KEY or dynamically via `api_key` param, to make the request.","messagePattern":"api_key is None\\. Please set AZURE_AI_API_KEY or dynamically via `api_key` param, to make the request\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/embed/handler.py","lineNumber":106,"sourceCode":"\n    def image_embedding(\n        self,\n        model: str,\n        data: ImageEmbeddingRequest,\n        timeout: float,\n        logging_obj,\n        model_response: EmbeddingResponse,\n        optional_params: dict,\n        api_key: str | None,\n        api_base: str | None,\n        client: HTTPHandler | AsyncHTTPHandler | None = None,\n    ):\n        if api_base is None:\n            raise ValueError(\n                \"api_base is None. Please set AZURE_AI_API_BASE or dynamically via `api_base` param, to make the request.\"\n            )\n        if api_key is None:\n            raise ValueError(\n                \"api_key is None. Please set AZURE_AI_API_KEY or dynamically via `api_key` param, to make the request.\"\n            )\n\n        if client is None or not isinstance(client, HTTPHandler):\n            client = HTTPHandler(timeout=timeout, concurrent_limit=1)\n\n        url: Final = f\"{api_base}/images/embeddings\"\n\n        response: Final = client.post(\n            url=url,\n            json=data,\n            headers={\"Authorization\": f\"Bearer {api_key}\"},\n        )\n\n        embedding_response: Final = response.json()\n        embedding_headers: Final = dict(response.headers)\n        returned_response: Final[EmbeddingResponse] = convert_to_model_response_object(\n            response_object=embedding_response,","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/embed/handler.py#L88-L124","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nlitellm.embedding(model='azure_ai/img-embed', input=[b64], api_base=base)\n\n# after\nlitellm.embedding(model='azure_ai/img-embed', input=[b64], api_base=base,\n                  api_key=os.environ['AZURE_AI_API_KEY'])","handlingStrategy":"validation","validationCode":"import os\n\ndef foundry_key() -> str:\n    key = os.getenv('AZURE_AI_API_KEY')\n    if not key:\n        raise RuntimeError('AZURE_AI_API_KEY is required for azure_ai embeddings')\n    return key","typeGuard":null,"tryCatchPattern":"try:\n    litellm.embedding(model='azure_ai/img', input=imgs, api_key=foundry_key())\nexcept ValueError as e:\n    if 'AZURE_AI_API_KEY' in str(e):\n        raise ConfigurationError('missing Foundry API key') from e\n    raise","preventionTips":["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."],"tags":["azure","embeddings","configuration","api-key","auth"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}