{"record":{"id":"8cfdd0bb978cb242","repo":"BerriAI/litellm","slug":"azure-ai-api-key-is-required-for-model-model-se","errorCode":null,"errorMessage":"Azure AI API key is required for model {model}. Set AZURE_AI_API_KEY environment variable or pass api_key parameter.","messagePattern":"Azure AI API key is required for model (.+?)\\. Set AZURE_AI_API_KEY environment variable or pass api_key parameter\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/image_edit/flux2_transformation.py","lineNumber":77,"sourceCode":"    def use_multipart_form_data(self) -> bool:\n        \"\"\"FLUX 2 uses JSON requests, not multipart/form-data.\"\"\"\n        return False\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        litellm_params: dict | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        \"\"\"\n        Validate Azure AI Foundry environment and set up authentication\n        \"\"\"\n        api_key = AzureFoundryModelInfo.get_api_key(api_key)\n\n        if not api_key:\n            raise ValueError(\n                f\"Azure AI API key is required for model {model}. Set AZURE_AI_API_KEY environment variable or pass api_key parameter.\"\n            )\n\n        headers.update(\n            {\n                \"Api-Key\": api_key,\n                \"Content-Type\": \"application/json\",\n            }\n        )\n        return headers\n\n    def transform_image_edit_request(\n        self,\n        model: str,\n        prompt: str | None,\n        image: FileTypes | None,\n        image_edit_optional_request_params: dict,\n        litellm_params: GenericLiteLLMParams,","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/image_edit/flux2_transformation.py#L59-L95","documentation":"The FLUX 2 image-edit transformation authenticates with an Api-Key header. It resolves the key via AzureFoundryModelInfo.get_api_key (parameter or AZURE_AI_API_KEY env var) and, if empty, raises ValueError telling you to set AZURE_AI_API_KEY or pass api_key. This is the Foundry (project) key, not an Azure AD token — FLUX endpoints on Foundry use key auth.","triggerScenarios":"litellm.image_edit(model='azure_ai/flux-2-...') without api_key and without AZURE_AI_API_KEY; passing an Azure AD token where the Foundry Api-Key is expected; env var empty string (falsy) which also triggers the raise.","commonSituations":"Same service used for chat with Azure AD auth and the key env var never set; AZURE_AI_API_KEY defined but blank in CI; confusion between AZURE_API_KEY (Azure OpenAI) and AZURE_AI_API_KEY (Foundry).","solutions":["Pass api_key set to the Foundry project key from the Azure AI Foundry 'Keys' page.","Or export AZURE_AI_API_KEY in the litellm process environment (verify it is non-empty).","In proxy config use api_key: os.environ/AZURE_AI_API_KEY on the flux deployment entry.","Note FLUX routes take Api-Key auth — do not substitute a bearer/AD token."],"exampleFix":"# before\nlitellm.image_edit(model='azure_ai/flux-2-dev', image=img, prompt='remove background')\n\n# after\nlitellm.image_edit(\n    model='azure_ai/flux-2-dev', image=img, prompt='remove background',\n    api_key=os.environ['AZURE_AI_API_KEY'],\n)","handlingStrategy":"validation","validationCode":"import os\n\ndef flux2_key() -> str:\n    key = os.getenv('AZURE_AI_API_KEY')\n    if not key:  # empty string also fails the handler's truthiness check\n        raise RuntimeError('AZURE_AI_API_KEY must be a non-empty Foundry key for FLUX image edit')\n    return key","typeGuard":null,"tryCatchPattern":"try:\n    litellm.image_edit(model='azure_ai/flux-2-dev', image=img, prompt=p, api_key=flux2_key())\nexcept ValueError as e:\n    if 'Azure AI API key is required' in str(e):\n        raise ConfigurationError(str(e)) from e\n    raise","preventionTips":["Remember FLUX routes use Api-Key auth, not Azure AD tokens — configure the Foundry key.","Assert AZURE_AI_API_KEY is non-empty at startup; blank values pass 'is set' checks but fail here.","Route all Foundry-authenticated calls through one helper that resolves the key once."],"tags":["azure","image-edit","flux","api-key","auth","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}