Haystack

Haystack is a Python framework for building production-ready LLM pipelines. It provides components for retrieval, generation, and processing that can be composed into pipelines. Respan gives you full observability over every pipeline run, component, and LLM call — and gateway routing through the OpenAI-compatible Respan endpoint.

Create an account at platform.respan.ai and grab an API key. For gateway, also add credits or a provider key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

1

Install packages

$pip install respan-exporter-haystack haystack-ai
2

Set environment variables

$export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

OPENAI_API_KEY is used for LLM requests. RESPAN_API_KEY is used to export traces to Respan.

3

Add RespanConnector to your pipeline

1import os
2from haystack import Pipeline
3from haystack.components.generators import OpenAIGenerator
4from respan_exporter_haystack import RespanConnector
5
6pipeline = Pipeline()
7pipeline.add_component("respan", RespanConnector(api_key=os.environ["RESPAN_API_KEY"]))
8pipeline.add_component("llm", OpenAIGenerator(model="gpt-4.1-nano"))
9pipeline.connect("respan", "llm")
10
11result = pipeline.run({"respan": {"prompt": "Tell me a joke about AI"}})
12print(result)
4

View your trace

Open the Traces page to see your pipeline run with component spans, LLM calls, and inputs/outputs.

Configuration

See the Haystack Exporter SDK reference for the full API.

ComponentDescription
RespanConnectorConnects pipelines to Respan for tracing.
RespanTracerAlternative tracing integration.
RespanGeneratorRoutes LLM calls through the Respan gateway.
RespanChatGeneratorChat-specific gateway component.

Attributes

Pass Respan attributes through the connector.

1result = pipeline.run({
2 "respan": {
3 "prompt": "Tell me a joke",
4 "customer_identifier": "user-123",
5 "metadata": {"team": "ml"},
6 }
7})
AttributeDescription
customer_identifierUser/customer identifier.
metadataCustom key-value pairs.

Prompts

Use Respan-managed prompts in Haystack pipelines.

1from respan_exporter_haystack import RespanGenerator
2
3generator = RespanGenerator(
4 api_key=os.environ["RESPAN_API_KEY"],
5 model="gpt-4.1-nano",
6 prompt_id="your-prompt-id",
7 prompt_version=1,
8)