Grow or Die Connect my product

Anthropic cache read and write cost by customer

6 min read

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.

Enable caching, then reuse the same prefix

Install the official Anthropic client and Grow or Die's versioned server SDK in a Node.js server project. The GOD package is distributed at the URL below; do not substitute an npm-registry version lookup.

npm install @anthropic-ai/sdk https://grow-or-die.com/sdk/grow-or-die-sdk-0.3.3.tgz

Set both server-side API keys, save the example as an .mjs file, and supply a real shared-context.txt above your selected model’s minimum cacheable length. Running it makes two billable Claude requests; it is not a free cache test.

import Anthropic from "@anthropic-ai/sdk";
import { GrowOrDie } from "@grow-or-die/sdk";
import { readFile } from "node:fs/promises";

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 sharedContext = await readFile("./shared-context.txt", "utf8");
const system = [{
  type: "text",
  text: sharedContext,
  cache_control: { type: "ephemeral", ttl: "5m" },
}];

try {
  for (const question of ["Summarize the document.", "List its limitations."]) {
    const message = await telemetry.context({
      accountId: "account_123",
      feature: "document-agent",
      promptVersion: "v7",
    }, () => anthropic.messages.create({
      model: "claude-sonnet-4-6",
      max_tokens: 800,
      system,
      messages: [{ role: "user", content: question }],
    }));
    console.log(message.usage); // Counters only, not the document or answer.
  }
} finally {
  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.

Verify a cache write on the first response and a positive cache_read_input_tokens on the second. This is an expected pattern, not a guaranteed hit: short prefixes, changed content or an expired TTL can prevent reuse. Do not label a run successful merely because both requests returned HTTP 200. Preserve the reported 5-minute and 1-hour write breakdowns rather than guessing duration from the request alone.

Worked cost boundary · synthetic USD example

Use illustrative per-million rates of $3 input, $3.75 five-minute write, $0.30 cache read and $15 output. A first response with 100 base-input tokens, 10,000 write tokens and 200 output tokens costs $0.0408. A second with 100 base-input tokens, 10,000 read tokens and 200 output tokens costs $0.0063. Together: $0.0471. These assumed counters are not an observed customer result or a promise that your requests will cache.

Each quantity is counted once. If a one-hour write is reported but its duration cannot be distinguished, stop: substituting a cheaper five-minute rate would understate cost. Use the Claude prompt caching cost calculator to isolate the reusable prefix; its total excludes the base-input suffix and output included here.

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.

Primary references