@tozil/anthropic
v0.1.1
Published
Tozil instrumentation for the Anthropic SDK
Maintainers
Readme
@tozil/anthropic
Tozil instrumentation for the Anthropic SDK.
Automatically tracks every messages.create() and messages.stream() call — model, tokens, latency — with zero code changes to your Anthropic usage.
Install
npm install @tozil/core @tozil/anthropicUsage
import { init } from "@tozil/core";
import { anthropic } from "@tozil/anthropic";
init({
apiKey: "tz_...",
instrumentations: [anthropic()],
});
// Use Anthropic as normal — tracking is automatic
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const message = await client.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }],
});How it works
The plugin monkey-patches messages.create() and messages.stream() on the Anthropic SDK prototype. It captures:
- Model name
- Input/output token counts (from
usagein the response) - Latency in milliseconds
- User and endpoint context (if set via
@tozil/core)
It does not capture prompts, completions, or any content.
Streaming support
Both messages.create({ stream: true }) and messages.stream() are fully supported. Token usage is captured from message_start and message_delta stream events.
License
MIT
