Anthropic Integration
Drop-in wrapper for the Anthropic SDK. Every Claude message, tool use, and streaming response is automatically traced with full token accounting.
Anthropic provides Claude models (Claude 3.5 Sonnet, Claude 3 Opus, Haiku) via API, used for chat, tool use, and extended thinking.

Getting Started
Install the SDK
Install @zespan/sdk alongside @anthropic-ai/sdk.
npm install @zespan/sdk @anthropic-ai/sdkWrap the Anthropic client
Pass your Anthropic client to wrapAnthropic(). All messages.create calls are traced, including streaming and tool use.
import Anthropic from '@anthropic-ai/sdk';
import { Zespan, wrapAnthropic } from '@zespan/sdk';
const lt = new Zespan({ apiKey: process.env.ZESPAN_API_KEY });
const anthropic = wrapAnthropic(new Anthropic(), lt);
const message = await anthropic.messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});View traces in Zespan
Open Trace Explorer. Claude calls appear with model, input/output tokens, cost, latency, and tool use as child spans.
What's captured automatically
- Input and output token counts per call
- USD cost per call and per model version
- Tool use spans: each tool call as a child span with inputs and outputs
- Extended thinking: thinking blocks and reasoning tokens tracked separately
- Streaming: traced end-to-end including time-to-first-token
- API errors: overloaded, rate limit, and content policy blocks with full context
FAQ
Does this work with Claude's extended thinking feature?
Yes. Extended thinking blocks and reasoning tokens are captured as separate attributes on the span so you can see where thinking tokens are being consumed.
Does streaming work?
Yes. Streaming responses are traced end-to-end. Time-to-first-token and total latency are both recorded.
Can I track tool use costs?
Yes. Each tool call and its result are captured as child spans. Token costs from tool use round-trips are attributed to the parent Claude call.
Start for free — 10K traces/month, no card needed
Anthropic integration works on all plans including the free tier.