{"record":{"id":"82f8c33bcf2af705","repo":"BerriAI/litellm","slug":"missing-azure-ai-api-key-a-call-is-being-made-to","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/ocr/transformation.py","lineNumber":57,"sourceCode":"        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        api_base: str | None = None,\n        litellm_params: dict | None = None,\n        **kwargs,\n    ) -> dict:\n        \"\"\"\n        Validate environment and return headers for Azure AI OCR.\n\n        Azure AI uses Bearer token authentication with AZURE_AI_API_KEY.\n        \"\"\"\n        # Get API key from environment if not provided\n        if api_key is None:\n            api_key = get_secret_str(AZURE_AI_OCR_API_KEY_ENV_VAR)\n\n        if api_key is None:\n            raise ValueError(\n                \"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\"\n            )\n\n        # Validate API base is provided\n        if api_base is None:\n            api_base = get_secret_str(\"AZURE_AI_API_BASE\")\n\n        if api_base is None:\n            raise ValueError(\n                \"Missing Azure AI API Base - Set AZURE_AI_API_BASE environment variable or pass api_base parameter\"\n            )\n\n        headers = {\n            \"Authorization\": f\"Bearer {api_key}\",\n            \"Content-Type\": \"application/json\",\n            **headers,\n        }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/ocr/transformation.py#L39-L75","documentation":"Raised by the Azure AI OCR (non-DI) path when no API key is available: neither an explicit api_key parameter nor AZURE_AI_API_KEY (AZURE_AI_OCR_API_KEY_ENV_VAR) is set. This handler authenticates with a Bearer token built from that key, so header construction aborts before any request. Note this is the azure_ai/ocr transformation, distinct from Document Intelligence which uses AZURE_DOCUMENT_INTELLIGENCE_API_KEY.","triggerScenarios":"Invoking the Azure AI OCR model (not azure_ai/doc-intelligence/...) while AZURE_AI_API_KEY is unset and no api_key is passed in the call or litellm_params.","commonSituations":"Confusing the two Azure OCR env vars (setting the Document Intelligence ones for the Azure AI path or vice versa); env var missing in containers/serverless; variable set but not exported to the running process.","solutions":["Set AZURE_AI_API_KEY in the runtime environment (export it / add to container or .env).","Or pass api_key explicitly on the OCR call.","Confirm you're using the env vars matching the model route: AZURE_AI_API_KEY/AZURE_AI_API_BASE for azure_ai OCR vs AZURE_DOCUMENT_INTELLIGENCE_* for doc-intelligence."],"exampleFix":"# before\nos.environ[\"AZURE_DOCUMENT_INTELLIGENCE_API_KEY\"] = \"...\"  # wrong var for azure_ai OCR\nresp = litellm.aocr(model=\"azure_ai/<ocr-model>\", document=doc)\n\n# after\nos.environ[\"AZURE_AI_API_KEY\"] = \"...\"\nos.environ[\"AZURE_AI_API_BASE\"] = \"https://my-resource.services.ai.azure.com\"\nresp = litellm.aocr(model=\"azure_ai/<ocr-model>\", document=doc)","handlingStrategy":"validation","validationCode":"import os\nassert os.getenv(\"AZURE_AI_API_KEY\"), \"AZURE_AI_API_KEY not set for azure_ai OCR\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.aocr(model=\"azure_ai/<model>\", document=doc)\nexcept ValueError as e:\n    if \"Missing Azure AI API Key\" in str(e):\n        raise ConfigError(\"set AZURE_AI_API_KEY for the azure_ai OCR route\") from e\n    raise","preventionTips":["Use AZURE_AI_API_KEY/AZURE_AI_API_BASE for azure_ai OCR; AZURE_DOCUMENT_INTELLIGENCE_* only for doc-intelligence models.","Add a startup env preflight for whichever Azure OCR route your app uses."],"tags":["azure","ocr","authentication","config","environment"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}