| name | clade-observability |
| description | Monitor Claude API calls — log tokens, latency, costs, errors, and
Use when working with observability patterns.
set up alerts for production Claude integrations.
Trigger with "anthropic monitoring", "claude observability",
"track claude usage", "anthropic logging".
|
| allowed-tools | Read, Write, Edit |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","anthropic","claude","monitoring","observability"] |
| compatibility | Designed for Claude Code |
Anthropic Observability
Overview
Every messages.create call should be instrumented. Track tokens, latency, cost, model, and errors.
Logging Wrapper
import Anthropic from '@claude-ai/sdk';
const client = new Anthropic();
async function trackedCreate(params: Anthropic.MessageCreateParams) {
const start = performance.now();
try {
const message = await client.messages.create(params);
const durationMs = Math.round(performance.now() - start);
const log = {
timestamp: new Date().toISOString(),
model: message.model,
input_tokens: message.usage.input_tokens,
output_tokens: message.usage.output_tokens,
cache_read_tokens: message.usage.cache_read_input_tokens || 0,
duration_ms: durationMs,
stop_reason: message.stop_reason,
estimated_cost: (message., message.),
};
.(, .(log));
message;
} (err) {
durationMs = .(performance.() - start);
.(, .({
: ().(),
: params.,
: err . ? err.?. : ,
: err . ? err. : ,
: err . ? err.?.[] : ,
: durationMs,
}));
err;
}
}
(): {
: <, [, ]> = {
: [, ],
: [, ],
: [, ],
};
[inputRate, outputRate] = rates[model] || [, ];
(usage. * inputRate + usage. * outputRate) / ;
}