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.

Checked 2026-11-22

·All guides·Models

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

python
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:

python
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

SymptomLikely cause
An error before any request is sentUPLINKSWITCH_API_KEY is unset in the process that runs the pipeline, so the Secret cannot resolve
Authentication error from the APIThe variable holds another vendor's key, or a revoked one
Not-found error on the first runapi_base_url carries a route after /v1, or model is not a catalog id
Works alone, fails in the pipelineA 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".

Questions and answers

api_base_url="https://api.uplinkswitch.com/v1". The component adds the chat route, so the value ends at /v1.

Yes, and they have to be: an embedder is its own component with its own model and endpoint arguments. This page recommends no embedding model; embedding prices are compared here, and the LlamaIndex guide covers that framework's equivalent.

Run the GET /v1/models request above with the same environment variable. A list back means the key is fine and the component's api_base_url or model needs a second look.
Join on Telegram
Help