deepset-ai/haystack · error

You must provide `azure_endpoint` or set the `AZURE_OPENAI_E

Error message

You must provide `azure_endpoint` or set the `AZURE_OPENAI_ENDPOINT` environment variable.

What it means

AzureOpenAIResponsesChatGenerator requires an Azure OpenAI service endpoint URL to construct its client. The library raises this ValueError when neither the `azure_endpoint` parameter nor the `AZURE_OPENAI_ENDPOINT` environment variable provides one, because without it no API base URL exists.

Source

Thrown at haystack/components/generators/chat/azure_responses.py:167

                    For detailed information on JSON mode, see the [OpenAI Structured Outputs documentation](https://platform.openai.com/docs/guides/structured-outputs#json-mode).
            - `reasoning`: A dictionary of parameters for reasoning. For example:
                - `summary`: The summary of the reasoning.
                - `effort`: The level of effort to put into the reasoning. Can be `low`, `medium` or `high`.
                - `generate_summary`: Whether to generate a summary of the reasoning.
                Note: OpenAI does not return the reasoning tokens, but we can view summary if its enabled.
                For details, see the [OpenAI Reasoning documentation](https://platform.openai.com/docs/guides/reasoning).
        :param tools:
            A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
        :param tools_strict:
            Whether to enable strict schema adherence for tool calls. If set to `True`, the model will follow exactly
            the schema provided in the `parameters` field of the tool definition, but this may increase latency.
        :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).
        """
        azure_endpoint = azure_endpoint or os.getenv("AZURE_OPENAI_ENDPOINT")
        if azure_endpoint is None:
            raise ValueError(
                "You must provide `azure_endpoint` or set the `AZURE_OPENAI_ENDPOINT` environment variable."
            )
        self._azure_endpoint = azure_endpoint
        self._azure_deployment = azure_deployment
        super(AzureOpenAIResponsesChatGenerator, self).__init__(  # noqa: UP008
            api_key=api_key,  # type: ignore[arg-type]
            model=self._azure_deployment,
            streaming_callback=streaming_callback,
            api_base_url=f"{self._azure_endpoint.rstrip('/')}/openai/v1",
            organization=organization,
            generation_kwargs=generation_kwargs,
            timeout=timeout,
            max_retries=max_retries,
            tools=tools,
            tools_strict=tools_strict,
            http_client_kwargs=http_client_kwargs,
        )

View on GitHub (pinned to e318778c9b)

Solutions

  1. Set the AZURE_OPENAI_ENDPOINT environment variable to your Azure OpenAI resource URL (e.g. https://<resource>.openai.azure.com/)
  2. Pass azure_endpoint='https://<resource>.openai.azure.com/' explicitly to the constructor
  3. If using YAML, load the endpoint with env_var: ${AZURE_OPENAI_ENDPOINT} in the component init parameters
  4. Verify the env var is actually exported/loaded in the runtime environment (print os.environ before init)

Example fix

// before
gen = AzureOpenAIResponsesChatGenerator()
// after
gen = AzureOpenAIResponsesChatGenerator(azure_endpoint="https://my-resource.openai.azure.com/", azure_deployment="gpt-4o")
Defensive patterns

Strategy: validation

Validate before calling

import os
endpoint = azure_endpoint or os.getenv("AZURE_OPENAI_ENDPOINT")
if not endpoint:
    raise SystemExit("Set AZURE_OPENAI_ENDPOINT (e.g. https://<resource>.openai.azure.com/) before init")

Prevention

When it happens

Trigger: Instantiating `AzureOpenAIResponsesChatGenerator(...)` with `azure_endpoint=None` (the default) while the `AZURE_OPENAI_ENDPOINT` env var is unset or empty.

Common situations: Deploying to an environment (CI, containers, serverless) where the .env file is not loaded; renaming the env var or using the wrong name (e.g. AZURE_OPENAI_BASE); forgetting to pass azure_endpoint in YAML pipeline config.

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/7bc5e1d2cab4d918. Report an issue: GitHub.