deepset-ai/haystack · critical

Please provide an Azure endpoint or set the environment vari

Error message

Please provide an Azure endpoint or set the environment variable AZURE_OPENAI_ENDPOINT.

What it means

AzureOpenAIChatGenerator needs an Azure OpenAI endpoint URL. If neither the azure_endpoint parameter nor the AZURE_OPENAI_ENDPOINT environment variable provides one, __init__ raises ValueError.

Source

Thrown at haystack/components/generators/chat/azure.py:210

        :param http_client_kwargs:
            A dictionary of keyword arguments to configure a custom `httpx.Client`or `httpx.AsyncClient`.
            For more information, see the [HTTPX documentation](https://www.python-httpx.org/api/#client).
        """
        # We intentionally do not call super().__init__ here because we only need to instantiate the client to interact
        # with the API.

        # Why is this here?
        # AzureOpenAI init is forcing us to use an init method that takes either base_url or azure_endpoint as not
        # None init parameters. This way we accommodate the use case where env var AZURE_OPENAI_ENDPOINT is set instead
        # of passing it as a parameter.
        azure_endpoint = azure_endpoint or os.environ.get("AZURE_OPENAI_ENDPOINT")
        # `azure_endpoint` accepts either a plain string or a `Secret`. We keep the original value on the instance for
        # serialization and resolve it to a string only to validate that an endpoint was provided.
        resolved_azure_endpoint = (
            azure_endpoint.resolve_value() if isinstance(azure_endpoint, Secret) else azure_endpoint
        )
        if not resolved_azure_endpoint:
            raise ValueError("Please provide an Azure endpoint or set the environment variable AZURE_OPENAI_ENDPOINT.")

        if api_key is None and azure_ad_token is None:
            raise ValueError("Please provide an API key or an Azure Active Directory token.")

        # The check above makes mypy incorrectly infer that api_key is never None,
        # which propagates the incorrect type.
        self.api_key = api_key  # type: ignore
        self.azure_ad_token = azure_ad_token
        self.generation_kwargs = generation_kwargs or {}
        self.streaming_callback = streaming_callback
        self.api_version = api_version
        self.azure_endpoint = azure_endpoint
        self.azure_deployment = azure_deployment
        self.organization = organization
        self.model = azure_deployment or "gpt-4.1-mini"
        self.timeout = timeout
        self.max_retries = max_retries
        self.default_headers = default_headers or {}

View on GitHub (pinned to e318778c9b)

Solutions

  1. Pass azure_endpoint="https://<your-resource>.openai.azure.com/" to the constructor
  2. Set the AZURE_OPENAI_ENDPOINT environment variable before running the app
  3. Verify the .env file is loaded (e.g. python-dotenv) and the variable name is spelled correctly

Example fix

// before
generator = AzureOpenAIChatGenerator()  # no endpoint anywhere
// after
import os
generator = AzureOpenAIChatGenerator(azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"])
# or set the env var: export AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com/
Defensive patterns

Strategy: validation

Validate before calling

import os
endpoint = azure_endpoint or os.getenv("AZURE_OPENAI_ENDPOINT")
if not endpoint:
    raise ValueError("Set azure_endpoint or AZURE_OPENAI_ENDPOINT")

Try / catch

try:
    generator = AzureOpenAIChatGenerator(azure_endpoint=endpoint)
except ValueError as e:
    logger.error("Azure configuration error: %s", e)
    raise

Prevention

When it happens

Trigger: Constructing AzureOpenAIChatGenerator() with azure_endpoint=None and no AZURE_OPENAI_ENDPOINT env var set (also no AZURE_OPENAI_SK/Secret resolution yielding a value).

Common situations: Deploying to an environment where the .env file wasn't loaded; running in CI where the env var is unset; typo in the environment variable name; passing an empty string as the endpoint.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30). Data as JSON: /api/errors/81d9c592e0874ee3. Report an issue: GitHub.