Haystack chat generator can't connect: the fixes

An OpenAIChatGenerator failing against the gateway points at api_base_url, the key Secret or the model id. Where each error is raised and how to fix it.

Checked 2026-11-22

·All fixes·Models

A Haystack OpenAIChatGenerator that cannot reach the gateway nearly always fails at one of three seams: the api_base_url argument, the Secret that carries the key, or the model value. This page is the troubleshooting companion to the Haystack setup guide, which has the working component and a pipeline around it; here you start from the error and trace it back. The base is https://api.uplinkswitch.com/v1.

Was the gateway reached at all?

Sort the failure first by where it was raised. If Haystack throws while the pipeline is being built, or before any request is sent, the gateway never saw anything and the cause is local, usually a Secret that could not resolve. If the error carries an HTTP status, the request arrived, and the status plus the code in the body name the setting at fault. Both kinds can look alike in a long traceback, so find the status line before you change any argument.

api_base_url decides where the request goes

The component sends its call to whatever api_base_url names, and the value should stop at /v1, since the component appends the chat route itself. A value that already ends in /chat/completions doubles the path, and the gateway answers that with a 404 carrying the code route_not_found.

Leaving the argument out entirely is the quieter mistake. The OpenAI client inside the component then falls back to its own default host, or to the OPENAI_BASE_URL variable when your environment sets one, so the call never comes here. A gateway key sent to OpenAI's host is refused there with OpenAI's own 401, which looks like a key fault but is really the endpoint never having changed. If the error body lacks this gateway's codes, check api_base_url before the key.

The key travels as a Secret

Secret.from_env_var stores the name of an environment variable rather than the key, and OpenAIChatGenerator resolves it while the component is constructed, so the variable must be set before the generator is built. Two cases follow:

  1. The variable is unset in the process that runs the pipeline, for example a worker or a container that never received it. Haystack raises before sending, so no status appears.
  2. The variable holds another vendor's key or a revoked one. The gateway answers 401 invalid_api_key with the message The API key is not valid.

Set the variable where the pipeline actually runs, not only in the shell you test from, and fill it with a current sk-uplink-live-... key. A key whose allowlist leaves out the model passes authentication and returns 403 scope_denied, not a 401.

model must be a catalog id

A 404 with the code model_not_found, once the base and the key are right, is the model argument. Pass the id exactly as the catalog prints it, with no provider prefix, and check it without a key:

bash
curl https://api.uplinkswitch.com/v1/catalog

If a pipeline that ran yesterday fails today on the same id, read that id's availability first. On the 2026-11-23 catalog gpt-6.1-sol read ok and deepseek-v4.1-flash read ok; an id flagged degraded means moving the generator to a sibling, not rebuilding the pipeline.

Run the generator on its own

When a pipeline fails, call the generator alone with one short message, outside the prompt builder and any retriever:

python
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret

gen = OpenAIChatGenerator(
    api_key=Secret.from_env_var("UPLINKSWITCH_API_KEY"),
    api_base_url="https://api.uplinkswitch.com/v1",
    model="gpt-6.1-sol",
)
print(gen.run([ChatMessage.from_user("ping")])["replies"][0].text)

This sends one billed model call. If the generator answers alone but the pipeline still fails, the fault sits in how the components are connected, not in the endpoint. If it fails alone, you have reproduced the connection problem in a dozen lines. An embedder is a separate component with its own model and endpoint arguments, so a working generator proves nothing about an embedding step; the LlamaIndex guide is the nearest comparison if you are weighing frameworks.

Questions and answers

OpenAIChatGenerator, through its api_base_url argument. Give it the gateway root ending in /v1; anything after that, such as /chat/completions, doubles the path into a 404 route_not_found.

Yes. The generator and the embedder are different components, each with its own model and endpoint settings. Test each on its own catalog id, because a chat generator that connects says nothing about whether the embedder will.

Look for the gateway's codes in the error body. A 401 invalid_api_key is the key, often a wrong value behind the Secret; a 404 route_not_found is the base URL path. An error with neither code usually means api_base_url was left out and the call went to OpenAI's host.
Join on Telegram
Help