Anthropic

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.

zespan.com — anthropic trace
Zespan trace showing a Claude API call with input/output tokens and tool use spans

Getting Started

1

Install the SDK

Install @zespan/sdk alongside @anthropic-ai/sdk.

bash
npm install @zespan/sdk @anthropic-ai/sdk
2

Wrap the Anthropic client

Pass your Anthropic client to wrapAnthropic(). All messages.create calls are traced, including streaming and tool use.

typescript
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' }],
});
3

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.

← All integrations