{"record":{"id":"b016a10817932f95","repo":"deepset-ai/haystack","slug":"please-provide-an-api-key-or-an-azure-active-direc-b016a1","errorCode":null,"errorMessage":"Please provide an API key or an Azure Active Directory token.","messagePattern":"Please provide an API key or an Azure Active Directory token\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/components/embedders/azure_text_embedder.py","lineNumber":110,"sourceCode":"            every request.\n        :param http_client_kwargs:\n            A dictionary of keyword arguments to configure a custom `httpx.Client`or `httpx.AsyncClient`.\n            For more information, see the [HTTPX documentation](https://www.python-httpx.org/api/#client).\n\n        \"\"\"\n        # We intentionally do not call super().__init__ here because we only need to instantiate the client to interact\n        # with the API.\n\n        # Why is this here?\n        # AzureOpenAI init is forcing us to use an init method that takes either base_url or azure_endpoint as not\n        # None init parameters. This way we accommodate the use case where env var AZURE_OPENAI_ENDPOINT is set instead\n        # of passing it as a parameter.\n        azure_endpoint = azure_endpoint or os.environ.get(\"AZURE_OPENAI_ENDPOINT\")\n        if not azure_endpoint:\n            raise ValueError(\"Please provide an Azure endpoint or set the environment variable AZURE_OPENAI_ENDPOINT.\")\n\n        if api_key is None and azure_ad_token is None:\n            raise ValueError(\"Please provide an API key or an Azure Active Directory token.\")\n\n        self.api_key = api_key  # type: ignore[assignment] # mypy does not understand that api_key can be None\n        self.azure_ad_token = azure_ad_token\n        self.api_version = api_version\n        self.azure_endpoint = azure_endpoint\n        self.azure_deployment = azure_deployment\n        self.model = azure_deployment\n        self.dimensions = dimensions\n        self.organization = organization\n        self.timeout = timeout\n        self.max_retries = max_retries\n        self.prefix = prefix\n        self.suffix = suffix\n        self.default_headers = default_headers or {}\n        self.azure_ad_token_provider = azure_ad_token_provider\n        self.http_client_kwargs = http_client_kwargs\n\n        self.client: AzureOpenAI | None = None","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/azure_text_embedder.py#L92-L128","documentation":"AzureTextEmbedder requires credentials to construct an Azure OpenAI client. The constructor raises this ValueError when neither an `api_key` nor an `azure_ad_token` is provided, because the underlying Azure SDK client cannot authenticate without one of them. Note the message says 'API key or Azure Active Directory token' — passing only an endpoint and deployment is not enough.","triggerScenarios":"Calling `AzureTextEmbedder(azure_endpoint=..., azure_deployment=...)` with both `api_key` and `azure_ad_token` left as None and no usable credential resolved.","commonSituations":"Deploying to an environment where the `AZURE_OPENAI_API_KEY` env var is not set; forgetting to pass the key after switching from the plain OpenAI embedder to the Azure variant; intending to use Entra ID auth but not supplying the token; keys defined in a different environment (e.g. CI secrets not injected).","solutions":["Pass `api_key=\"...\"` to the constructor","Or pass `azure_ad_token=\"...\"` for Azure Active Directory authentication","Or set the AZURE_OPENAI_API_KEY environment variable, which the default init parameter reads","Verify the credential is actually present in the runtime environment (print/debug os.environ in the failing context)"],"exampleFix":"// before\nembedder = AzureTextEmbedder(azure_endpoint=\"https://myres.openai.azure.com\", azure_deployment=\"my-deployment\")\n// after\nembedder = AzureTextEmbedder(azure_endpoint=\"https://myres.openai.azure.com\", azure_deployment=\"my-deployment\", api_key=os.environ[\"AZURE_OPENAI_API_KEY\"])","handlingStrategy":"validation","validationCode":"import os\nassert (os.environ.get(\"AZURE_OPENAI_API_KEY\") or api_key or azure_ad_token), \"Provide api_key, azure_ad_token, or set AZURE_OPENAI_API_KEY\"\nembedder = AzureTextEmbedder(api_key=api_key, azure_ad_token=azure_ad_token)","typeGuard":"def has_azure_credentials(api_key=None, azure_ad_token=None) -> bool:\n    return bool(api_key or azure_ad_token or os.environ.get(\"AZURE_OPENAI_API_KEY\"))","tryCatchPattern":null,"preventionTips":["Store AZURE_OPENAI_API_KEY in the deployment environment's secret manager","Assert credentials exist in test setup before constructing Azure components","Prefer env-var configuration so the same code works locally and in CI"],"tags":["authentication","azure","configuration","python"],"backgroundTag":"missing-api-key","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}