Skip to navigation

Tracing quickstart

Install the Respan SDK and see your first trace in Logs.

Tracing records each step of your AI app, such as LLM calls, tool runs, and agent steps, as a tree of spans, so you can debug failures and see where time and cost go. The Respan SDK traces the major LLM SDKs automatically once you initialize it.

Set up with your coding agent

Paste this prompt into Claude Code, Cursor, Codex, or any coding agent:

Help me set up Respan tracing: fetch and follow https://respan.ai/docs/agent-setup.md

To set it up yourself, follow the steps below.

Step by step

1

Create an API key

In the platform, go to Gateway › API keys and click New key. Pick Production or Test, keep the default permissions, and click Create.

The Create new key dialog with Name, Environment (Production or Test), and Permissions: Read, Write, Gateway, and Admin

Click Copy, then Done. You won’t see the key again, so save it now:

export RESPAN_API_KEY="your-respan-api-key"
2

Install and initialize the SDK

Install the Respan SDK alongside your LLM SDK. Initialize Respan once, before your first model call.

Requires Python 3.11 to 3.13.

pip install respan-ai openai
app.py
from openai import OpenAI
from respan import Respan, workflow
respan = Respan() # reads RESPAN_API_KEY
client = OpenAI() # reads OPENAI_API_KEY
@workflow(name="support_agent")
def support_agent(question: str) -> str:
response = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": question}],
)
return response.choices[0].message.content
print(support_agent("How do I rotate my API key?"))

Calls made with the OpenAI, Anthropic, AWS Bedrock, Vertex AI, and Together AI SDKs are traced automatically, plus Google GenAI and Ollama in Python, and Cohere, OpenRouter, and Writer in TypeScript. The workflow wrapper groups the calls inside it into one trace.

Using an agent framework such as OpenAI Agents, LangChain, or the Vercel AI SDK? Find its guide in Integrations.

3

Run your app

export OPENAI_API_KEY="your-openai-api-key"
python app.py # TypeScript: npx tsx app.mts

The SDK sends spans in the background and flushes them when the process exits. In serverless functions, call respan.flush() (await respan.flush() in TypeScript) before you return.

4

See the trace in Logs

Go to Observability › Logs. Open the grouping menu, which shows Spans by default, and pick Traces. Click your support_agent trace.

The side panel shows the span tree with each span’s duration, tokens, and cost. Click a span to see its input and output.

The trace side panel: a span tree for support_agent with classify_intent, openai.chat, search_docs, write_reply, and anthropic.chat, each with its duration, tokens, and cost, next to the selected support_agent span's input and output

Don’t see it? Widen the time range. Traces sent with a Test key show under Test, so set the environment switch to Test or All environments. See Inspect spans and traces.

Key terms

The grouping menu in Logs switches between these views.

TermWhat it is
SpanOne recorded operation, such as an LLM call, a tool run, or a function you wrapped
TraceAll the spans from one request or workflow run, linked into a tree
ThreadSpans that share a thread ID, such as the turns of one conversation