{"record":{"id":"1ebe9c87c46066bc","repo":"BerriAI/litellm","slug":"azure-ai-api-key-is-required-please-set-azure-ai","errorCode":null,"errorMessage":"Azure AI API key is required. Please set 'AZURE_AI_API_KEY' or 'litellm.azure_key'","messagePattern":"Azure AI API key is required\\. Please set 'AZURE_AI_API_KEY' or 'litellm\\.azure_key'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/rerank/transformation.py","lineNumber":72,"sourceCode":"                api_base=str(original_url.copy_with(path=normalized_path or \"/\")),\n                ending_path=\"/rerank\",\n            )\n\n        # Backwards compatible default: Azure AI rerank was originally exposed under /v1/rerank\n        return _add_path_to_api_base(api_base=api_base, ending_path=\"/v1/rerank\")\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        optional_params: dict | None = None,\n    ) -> dict:\n        if api_key is None:\n            api_key = get_secret_str(\"AZURE_AI_API_KEY\") or litellm.azure_key\n\n        if api_key is None:\n            raise ValueError(\"Azure AI API key is required. Please set 'AZURE_AI_API_KEY' or 'litellm.azure_key'\")\n\n        default_headers: Final = {\n            \"Authorization\": f\"Bearer {api_key}\",\n            \"accept\": \"application/json\",\n            \"content-type\": \"application/json\",\n        }\n\n        # If 'Authorization' is provided in headers, it overrides the default.\n        if \"Authorization\" in headers:\n            default_headers[\"Authorization\"] = headers[\"Authorization\"]\n\n        # Merge other headers, overriding any default ones except Authorization\n        return {**default_headers, **headers}\n\n    def transform_rerank_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/rerank/transformation.py#L54-L90","documentation":"The Azure AI rerank auth header is a Bearer token built from an API key. validate_environment checks the api_key parameter, then AZURE_AI_API_KEY, then the global litellm.azure_key; if all are None it cannot construct the Authorization header and raises. Unlike Azure OpenAI, no AzureEntraID/managed-identity fallback applies here.","triggerScenarios":"litellm.rerank(model='azure_ai/...', ...) with no api_key argument while AZURE_AI_API_KEY is unset and litellm.azure_key was never assigned. Setting only AZURE_API_KEY (the Azure OpenAI var) does not satisfy this check.","commonSituations":"Reusing Azure OpenAI env var names (AZURE_API_KEY) for Azure AI resource calls; rotating keys and clearing the env var; proxy model entry with api_key omitted.","solutions":["export AZURE_AI_API_KEY=<your-key> (note: AZURE_AI_API_KEY, not AZURE_API_KEY)","Or pass api_key directly to litellm.rerank(...)","Or set the global: litellm.azure_key = '<your-key>'"],"exampleFix":"# before\nos.environ['AZURE_API_KEY'] = key  # wrong variable\nlitellm.rerank(model='azure_ai/cohere-rerank-v3.5', query=q, documents=docs, api_base=base)\n\n# after\nos.environ['AZURE_AI_API_KEY'] = key\nlitellm.rerank(model='azure_ai/cohere-rerank-v3.5', query=q, documents=docs, api_base=base)","handlingStrategy":"validation","validationCode":"api_key = os.environ.get('AZURE_AI_API_KEY')\nassert api_key, 'Set AZURE_AI_API_KEY (not AZURE_API_KEY) for azure_ai rerank'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use distinct, correctly-named env vars per Azure surface (AZURE_AI_API_KEY vs AZURE_API_KEY)","Fail fast at app startup if required keys are missing"],"tags":["azure","rerank","authentication","missing-parameter"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}