Haystack with an OpenAI-compatible chat generator
Set api_base_url on Haystack's OpenAIChatGenerator to use Claude, GPT and other catalog models: Secret handling, one pipeline step, and a connection check.
Haystack's OpenAIChatGenerator accepts a custom endpoint through its api_base_url argument, so pointing it at https://api.uplinkswitch.com/v1 with a catalog id as model is the whole connection. The argument names below match the Haystack documentation (version 3.5) for that component as read on 2026-11-22; the snippet was checked against the docs and not run.
Connect one chat generator
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret
llm = OpenAIChatGenerator(
api_key=Secret.from_env_var("UPLINKSWITCH_API_KEY"),
api_base_url="https://api.uplinkswitch.com/v1",
model="gpt-6.1-sol",
)
result = llm.run([ChatMessage.from_user("Name one use for a vector index.")])
print(result["replies"][0].text)Secret.from_env_var keeps the key out of a serialized pipeline: when Haystack writes the pipeline to YAML it stores the variable's name, not its value. Without an explicit api_key the component reads OPENAI_API_KEY, which is an easy way to send the wrong credential to the right URL.
gpt-6.1-sol shows availability ok on the catalog snapshot of 2026-11-23, at $0.582 / $2.91 per 1M tokens (in / out).
Put it in a pipeline
The generator's usual place is after a ChatPromptBuilder, with the builder's prompt output connected to the generator's messages input:
from haystack import Pipeline
from haystack.components.builders import ChatPromptBuilder
pipe = Pipeline()
pipe.add_component("prompt_builder", ChatPromptBuilder())
pipe.add_component("llm", llm)
pipe.connect("prompt_builder.prompt", "llm.messages")That is one generation step. Retrievers, embedders and document stores are separate components with separate settings, and swapping the generator's endpoint says nothing about them.
When the call fails
| Symptom | Likely cause |
|---|---|
| An error before any request is sent | UPLINKSWITCH_API_KEY is unset in the process that runs the pipeline, so the Secret cannot resolve |
| Authentication error from the API | The variable holds another vendor's key, or a revoked one |
| Not-found error on the first run | api_base_url carries a route after /v1, or model is not a catalog id |
| Works alone, fails in the pipeline | A connection or template issue upstream of the generator, not the endpoint |
To separate a key problem from the rest, list models with the same key: curl https://api.uplinkswitch.com/v1/models -H "Authorization: Bearer $UPLINKSWITCH_API_KEY".