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 Anthropic Agents SDK?
The Anthropic Agents 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.
Setup
The Anthropic Agents SDK uses an exporter pattern rather than the standard
Respan() instrumentor pattern. The exporter wraps query() calls to capture traces.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
ANTHROPIC_API_KEY by routing calls through the Respan gateway.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. |
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. |
Decorators
The Anthropic Agents SDK uses the exporter pattern rather than@workflow/@task decorators. All lifecycle events are captured automatically by the exporter.
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.Streaming
Theexporter.query() method streams messages as they arrive.
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. |
Gateway
You can route all Anthropic calls through the Respan gateway by setting environment variables:ClaudeAgentOptions.env: