Claude prompt caching has three economically different meters: cache reads, five-minute cache writes, and one-hour cache writes. Preserve each provider-reported field, attach the call to an opaque account, and price the event on the server with the rate effective on that date.
Do not flatten cache usage into input tokens
Anthropic reports cache_read_input_tokens and cache_creation_input_tokens. Cache creation can also distinguish five-minute and one-hour ephemeral writes. The published pricing model assigns different rates to base input, cache hits, five-minute writes, one-hour writes, and output.
Observed Claude cost = base input + 5-minute cache writes + 1-hour cache writes + cache reads + output.
Wrap the official Claude client on the server
import Anthropic from "@anthropic-ai/sdk";
import { GrowOrDie } from "@grow-or-die/sdk";
const telemetry = new GrowOrDie({
ingestKey: process.env.GROW_OR_DIE_KEY,
});
const anthropic = telemetry.wrapAnthropic(new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
maxRetries: 0,
}));
const message = await telemetry.context({
accountId: "account_123",
feature: "document-agent",
promptVersion: "v7",
}, () => anthropic.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 800,
messages: [{ role: "user", content: "Your application input" }],
}));
await telemetry.flush();
The wrapper records provider usage and fixed operational metadata. It does not send the prompt, generated message, API key, authorization header, or customer email.
Worked cost boundary
Assume a response reports ordinary input, a five-minute cache write, cache-read tokens, and output tokens. Price each count independently with the exact model's effective rates. If the response used a one-hour cache write but the event cannot distinguish that duration, stop: a cheaper five-minute rate would understate cost.
Unknown is not zero. Keep calls, tokens, latency, and status visible while withholding customer profit until every non-zero billable meter has a trusted price.
Join usage to the payer through a canonical account
Attach a stable internal account ID before the model call, then link that account to the payment provider's customer ID through a separate server-side identity event. This separates identity from content and prevents email changes from moving historical cost between customers.
What this evidence can and cannot prove
Cache usage proves only what the completed Claude response reports. It does not prove that every provider-side retry was observed or that a payer link is correct. Unknown cache duration, inference region, speed, model, or final usage blocks a complete cost result.