Set up Respan
Set up Respan
- Sign up — Create an account at platform.respan.ai
- Create an API key — Generate one on the API keys page
- Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page
Use AI
Use AI
Add the Docs MCP to your AI coding tool to get help building with Respan. No API key needed.
What is Claude Agent SDK?
The Claude Agent SDK (claude-agent-sdk) is a framework for building agent workflows powered by Claude. It supports tool use, sub-agent delegation, and structured conversations. The Respan exporter hooks into the SDK’s lifecycle events to capture full trace data.
Example projects
Example projects
Setup
Set environment variables
RESPAN_API_KEY is used for trace export. ANTHROPIC_API_KEY is used by the Claude Agent SDK to call Anthropic directly.Using the Respan gateway instead?
Using the Respan gateway instead?
You can skip Pass the gateway URL and key via See the full gateway guide for more details.
ANTHROPIC_API_KEY by routing calls through the Respan gateway. The gateway uses your RESPAN_API_KEY for both the LLM call and trace export.ClaudeAgentOptions.env:View your trace
Open the Traces page to see your agent trace.
Configuration
- Python
- JavaScript
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | RESPAN_API_KEY env var | Respan API key. |
base_url | str | RESPAN_BASE_URL env var | API base URL. |
endpoint | str | None | None | Custom ingest endpoint URL. |
timeout_seconds | int | 15 | HTTP timeout for trace export. |
max_retries | int | 3 | Retry attempts for failed exports. |
Examples
Wrapped query
The simplest integration pattern —exporter.query() handles tracing hooks automatically.
Tool use
Tool calls are automatically captured as child spans with inputs and outputs. Specify allowed tools viaClaudeAgentOptions.
Streaming
Theexporter.query() method streams messages as they arrive. Handle each message type.
SystemMessage, UserMessage, AssistantMessage, ResultMessage, StreamEvent.
Attributes
The exporter automatically captures:| Attribute | Source | Description |
|---|---|---|
session_id | SystemMessage | Unique session identifier |
input_tokens | AssistantMessage.usage | Prompt token count |
output_tokens | AssistantMessage.usage | Completion token count |
cache_creation_input_tokens | AssistantMessage.usage | Cache creation tokens |
cache_read_input_tokens | AssistantMessage.usage | Cache read tokens |
model | AssistantMessage | Model name used |
Traced events
The exporter hooks into five SDK lifecycle events:| Event | Span Type | Description |
|---|---|---|
UserPromptSubmit | task | User submits a prompt |
PreToolUse | — | Tool invocation starts (paired with PostToolUse) |
PostToolUse | tool | Tool completes with input/output |
SubagentStop | task | Sub-agent finishes execution |
Stop | — | Root agent terminates |
Looking for gateway integration? See Gateway > Claude Agent SDK.