A
Anthropic
Wrap the Anthropic Claude SDK in TypeScript or Python. Messages, streams, tools, and thinking traced with tokens, cache usage, and cost.
Built by
telemetry.dev
Language
TypeScript + Python
Packages
@telemetry-dev/anthropic · telemetry-dev-anthropic
Category
Model providers
Docs
About the Anthropic integration
@telemetry-dev/anthropic (TypeScript) and telemetry-dev-anthropic (Python) wrap the official Anthropic SDKs and emit OpenTelemetry GenAI spans. messages.create and the messages.stream helper are traced — including stream: true responses — with model, system instructions, tools, messages, finish reason, and token usage with cache and thinking token details when Anthropic returns them.
Key features
- Full Messages coverage: Requests capture model, max tokens, sampling params, stop sequences, system instructions, tools, and messages; responses capture content blocks, finish reason, and usage.
- Streaming done right: Spans start at request time and aggregate text, tool input fragments, thinking deltas, and usage until the stream is consumed, closed, or errors.
- Bedrock and Vertex clients too: Anthropic, Bedrock, and Vertex clients are all supported, with provider recorded as
anthropic,aws.bedrock, orgcp.vertex_ai. - Cache and thinking tokens: Cache read/write and thinking token details flow through when the API returns them, so cost stays accurate.
- Per-client or global:
wrapAnthropic(client)is idempotent;instrumentAnthropic()patches once at startup.
Get started
import Anthropic from "@anthropic-ai/sdk";
import { init, shutdown } from "@telemetry-dev/sdk";
import { wrapAnthropic } from "@telemetry-dev/anthropic";
init({ serviceName: "anthropic-worker" });
const anthropic = wrapAnthropic(new Anthropic());
await anthropic.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 256,
messages: [{ role: "user", content: "Say hello." }],
});
await shutdown();
In Python, wrap_anthropic also covers AsyncAnthropic, AnthropicBedrock, and AnthropicVertex clients:
import telemetry_dev
from anthropic import Anthropic
from telemetry_dev_anthropic import wrap_anthropic
telemetry_dev.init()
client = wrap_anthropic(Anthropic())
client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hello"}],
)