---
title: "Tracing quickstart"
subtitle: "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
```

<img src={"/docs/images/logs/logs-overview-light.webp"} className="block dark:hidden" alt="Logs listing traced LLM calls such as openai.chat and anthropic.chat, with span counts, error rates over time, and each call's model, system prompt, and user message"/>
<img src={"/docs/images/logs/logs-overview-dark.webp"} className="hidden dark:block" alt="Logs listing traced LLM calls such as openai.chat and anthropic.chat, with span counts, error rates over time, and each call's model, system prompt, and user message"/>

To set it up yourself, follow the [steps below](#step-by-step).

## Step by step

<Steps>
<Step title="Create an API key">

In the [platform](https://platform.respan.ai), go to **API keys** and click **New key**. Pick **Production** or **Test**, keep the default permissions, and click **Create**.

<img src={"/docs/images/gateway-quickstart/create-api-key-light.webp"} width="420" className="block dark:hidden" alt="The Create new key dialog with Name, Environment (Production or Test), and Permissions: Read, Write, Gateway, and Admin" />
<img src={"/docs/images/gateway-quickstart/create-api-key-dark.webp"} width="420" className="hidden dark:block" alt="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:

```bash
export RESPAN_API_KEY="your-respan-api-key"
```

</Step>
<Step title="Install and initialize the SDK">

Install the Respan SDK alongside your LLM SDK. Initialize Respan once, before your first model call. Your model calls are then traced with no other changes.

<Tabs>
<Tab title="Python">
Requires Python 3.11 to 3.13.

```bash
pip install respan-ai openai
```

```python app.py
from openai import OpenAI
from respan import Respan

respan = Respan()  # reads RESPAN_API_KEY
client = OpenAI()  # reads OPENAI_API_KEY

response = client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "How do I rotate my API key?"}],
)
print(response.choices[0].message.content)
```
</Tab>
<Tab title="TypeScript">
```bash
npm install @respan/respan openai
```

```typescript app.mts
import OpenAI from "openai";
import { Respan } from "@respan/respan";

const respan = new Respan(); // reads RESPAN_API_KEY
await respan.initialize();
const client = new OpenAI(); // reads OPENAI_API_KEY

const response = await client.chat.completions.create({
  model: "gpt-5.5",
  messages: [{ role: "user", content: "How do I rotate my API key?" }],
});
console.log(response.choices[0].message.content);
```
</Tab>
</Tabs>

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.

Using an agent framework such as OpenAI Agents, LangChain, or the Vercel AI SDK? Find its guide in [Integrations](/docs/integrations/overview).

</Step>
<Step title="Run your app">

```bash
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.

</Step>
<Step title="See the call in Logs">

Go to **Observability** › **Logs**. Your `openai.chat` span is at the top, with its model, duration, tokens, and cost. Click it to see the 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](/docs/documentation/features/observe/view-debug-traces).

</Step>
</Steps>

## Key terms

The grouping menu in Logs switches between these views.

| Term | What it is |
|------|------------|
| **Span** | One recorded operation, such as an LLM call, a tool run, or a function you wrapped |
| **Trace** | All the spans from one request, linked into a tree |
| **Thread** | Spans that share a thread ID, such as the turns of one conversation |
