Claude Agent SDK
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
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) lets you run Claude-powered agent sessions with tool use, multi-turn reasoning, and streamed events. Respan traces the SDK through OpenInference, so a normal claude_agent_sdk.query() call shows up in the Traces view with agent spans, tool activity, and request metadata.
If you’re new to the wrapper used on this page, start with the OpenInference Instrumentor guide.
Example project
Setup
Install packages
This is the tested minimal package set for the example on this page. Use a clean virtual environment so the OpenTelemetry dependencies resolve to this working set.
Set environment variables
RESPAN_API_KEY sends traces to Respan. ANTHROPIC_API_KEY is the simplest way to let Claude Agent SDK authenticate with Anthropic.
If you already use Claude Code locally, claude auth login also works. The environment variable is just the simplest example path.
View your trace
Open the Traces page to see the Claude Agent SDK run, including the root agent span and any tool calls.
What gets traced
All Claude Agent SDK operations are auto-instrumented through OpenInference:
query()runs and final results- Agent spans and step metadata emitted by the SDK
- Tool calls and tool outputs
- Session and model metadata
- Token usage when the SDK exposes it
Traces appear in the Traces dashboard.
Configuration
Attributes
In Respan()
Set defaults at initialization. These apply to all spans created in the current process.
With propagate_attributes
Override attributes per request using a context manager.
Decorators (optional)
Decorators are not required. The OpenInference instrumentor already traces Claude Agent SDK calls automatically. Use @workflow and @task when you want to add structure around one or more agent runs.
Examples
Basic
Run a single Claude Agent SDK query and print the assistant reply.
Streaming message flow
The SDK emits multiple message objects during a run. You can inspect the flow while Respan traces the full session.
Learn more
- OpenInference Instrumentor - How the generic OpenInference wrapper works with Respan
- OpenTelemetry integration - How Respan processes OTel spans
- Respan Python SDK - Full SDK reference