{"record":{"id":"da90f5d56dd8959d","repo":"BerriAI/litellm","slug":"missing-azure-document-intelligence-api-key-set","errorCode":null,"errorMessage":"Missing Azure Document Intelligence API Key - Set AZURE_DOCUMENT_INTELLIGENCE_API_KEY environment variable or pass api_key parameter","messagePattern":"Missing Azure Document Intelligence API Key - Set AZURE_DOCUMENT_INTELLIGENCE_API_KEY environment variable or pass api_key parameter","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/ocr/document_intelligence/transformation.py","lineNumber":224,"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 Document Intelligence.\n\n        Authentication uses Ocp-Apim-Subscription-Key header.\n        \"\"\"\n        # Get API key from environment if not provided\n        if api_key is None:\n            api_key = get_secret_str(AZURE_DOCUMENT_INTELLIGENCE_API_KEY_ENV_VAR)\n\n        if api_key is None:\n            raise ValueError(\n                \"Missing Azure Document Intelligence API Key - Set AZURE_DOCUMENT_INTELLIGENCE_API_KEY environment variable or pass api_key parameter\"\n            )\n\n        # Validate API base/endpoint is provided\n        if api_base is None:\n            api_base = get_secret_str(\"AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT\")\n\n        if api_base is None:\n            raise ValueError(\n                \"Missing Azure Document Intelligence Endpoint - Set AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT environment variable or pass api_base parameter\"\n            )\n\n        headers = {\n            \"Ocp-Apim-Subscription-Key\": api_key,\n            \"Content-Type\": \"application/json\",\n            **headers,\n        }\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/ocr/document_intelligence/transformation.py#L206-L242","documentation":"Raised while building request headers for Azure Document Intelligence OCR when no API key is available: neither an explicit api_key parameter nor the AZURE_DOCUMENT_INTELLIGENCE_API_KEY environment variable is set. Azure DI authenticates via the Ocp-Apim-Subscription-Key header, which cannot be constructed without the key, so the call is aborted before any request.","triggerScenarios":"Calling litellm OCR with an 'azure_ai/doc-intelligence/...' model while AZURE_DOCUMENT_INTELLIGENCE_API_KEY is unset in the process environment and no api_key is passed in params/litellm_params.","commonSituations":"Env var set in a shell but not exported (or set after the process started; missing from docker/systemd/serverless env); typo in the variable name; assuming AZURE_AI_API_KEY covers DI (it doesn't — DI needs its own key).","solutions":["Set AZURE_DOCUMENT_INTELLIGENCE_API_KEY in the environment of the running process (export it, add to .env/secret manager, or docker env).","Or pass the key explicitly: litellm.oclr(..., api_key='...', api_base='https://<resource>.cognitiveservices.azure.com').","In a server, confirm the variable is present via os.environ before the call, and reload/redeploy after adding it."],"exampleFix":"# before\nos.environ[\"AZURE_AI_API_KEY\"] = \"...\"  # wrong variable for DI\nresp = litellm.aocr_document(model=\"azure_ai/doc-intelligence/prebuilt-read\", document=doc)\n\n# after\nos.environ[\"AZURE_DOCUMENT_INTELLIGENCE_API_KEY\"] = \"...\"\nos.environ[\"AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT\"] = \"https://myres.cognitiveservices.azure.com\"\nresp = litellm.aocr_document(model=\"azure_ai/doc-intelligence/prebuilt-read\", document=doc)","handlingStrategy":"validation","validationCode":"import os\nassert os.getenv(\"AZURE_DOCUMENT_INTELLIGENCE_API_KEY\") or passed_api_key, \"DI key missing\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.aocr_document(model=\"azure_ai/doc-intelligence/prebuilt-read\", document=doc)\nexcept ValueError as e:\n    if \"Missing Azure Document Intelligence API Key\" in str(e):\n        raise ConfigError(\"set AZURE_DOCUMENT_INTELLIGENCE_API_KEY\") from e\n    raise","preventionTips":["Add a startup preflight check for AZURE_DOCUMENT_INTELLIGENCE_API_KEY in the service env.","Don't reuse AZURE_AI_API_KEY for DI — they are separate credentials."],"tags":["azure","document-intelligence","ocr","authentication","config","environment"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}