Skip to main content
Back to all essays
System Design5 min read

Claude prompt caching: measure reuse before choosing a TTL

A worked API cost example shows when a five-minute cache helps, when a one-hour cache wins, and how to diagnose misses without freezing live business data.

Illustrative prompt-cache comparison with a 6,000-token stable prefix and 1,000 fresh tokens per request. Four requests ten minutes apart create four five-minute writes or one one-hour write and three reads; example input costs are USD 0.0680 and USD 0.0338.
Open full-size workflow diagram
Read the workflow steps
  1. Keep the reviewed tools and instructions in a stable 6,000-token prefix. Put each request’s current shipment data in a fresh 1,000-token suffix. Token counts are illustrative.
  2. For four requests at minute 0, 10, 20 and 30, a five-minute cache expires between requests. The example charges four writes.
  3. A one-hour cache can reuse the same prefix for the three later requests. The example charges one write and three reads, provided the prefix matches and the cache is available.
  4. At the cited Sonnet 5.5 standard API rates, illustrative input costs are USD 0.0680 versus USD 0.0338. Output and tool costs are excluded. Measure actual usage and business quality before selecting a lifetime.
Cover graphic for Claude prompt caching: measure reuse before choosing a TTL, System Design

A freight desk assistant may read the same operating instructions for every shipment while the shipment record changes on every request. That is a useful place to investigate prompt caching. The engineering question is how much of each request really stays identical, how long it stays reusable, and whether the extra cache-write cost earns its way back.

Consider a fictional assistant with a 6,000-token prefix containing reviewed tools and operating instructions. Each shipment adds 1,000 fresh input tokens. We will compare four requests, using arithmetic rather than an API benchmark. No customer savings or latency measurement is claimed.

Put current business records after the reusable prefix

Claude caches prompt prefixes. Its documented order is tools, system, then messages. An explicit cache boundary can end the stable material before a changing suffix. The default lifetime is five minutes, with a one-hour option; successful reuse refreshes the entry. Minimum cacheable length depends on the model. Check actual cache usage instead of assuming a marker created an entry. Claude: cache boundaries, lifetimes and minimums

Proposed request layout, not a complete API payload
REUSABLE PREFIX
  tool definitions: shipment-read-v2
  instructions: exception-review-v4
  explicit cache boundary

FRESH REQUEST SUFFIX
  shipment_id: S-204
  source_version: 18
  current carrier event + observation time

For this design, I would fetch the latest shipment version for every decision that needs it. A tariff update produces a new policy version and a changed prefix. Keep that change visible even if it causes a miss. Preserving an obsolete rate sheet to improve a cache-hit chart would defeat the purpose of the assistant.

Place the case ID and request timestamp in the changing suffix. Keep tool ordering deterministic. A useful pilot log stores a fingerprint of the reusable prefix and its policy version, so an operator can distinguish a deliberate update from accidental request churn. The application still checks access to every source it reads.

Calculate both writes and reads

The standard Claude Sonnet 5.5 API rates checked on October 19, 2026 are USD 2 per million ordinary input tokens, USD 2.50 for five-minute cache writes, USD 4 for one-hour writes and USD 0.10 for cache reads. The example excludes output, tools, regional modifiers and other pricing options. These API rates do not describe Claude subscription allowance consumption. Claude: current model and prompt-cache pricing

With four uncached requests, the illustrative input cost is 28,000 × 2 / 1,000,000 = USD 0.0560. If all later requests hit a five-minute cache, its prefix costs one 6,000-token write and three reads. The four changing suffixes cost 4,000 ordinary input tokens. Together that is 0.0150 + 0.0018 + 0.0080 = USD 0.0248.

Four-request examples using the same 6,000-token prefix
Request timingFive-minute input costOne-hour input cost
Minute 0, 2, 4, 6; each later request hitsUSD 0.0248USD 0.0338
Minute 0, 10, 20, 30; five-minute entries expireUSD 0.0680USD 0.0338
No caching, either timingUSD 0.0560USD 0.0560

The one-hour entry costs more to create. In the short burst it loses to the five-minute option, even though both reuse the prefix. Across ten-minute gaps it wins in this example because the five-minute plan pays four writes. Every amount in the table assumes the stated hit pattern; an actual hit count must come from the response, not from the expected schedule.

The gaps are measured between request starts. Claude documents that a cache lifetime begins at the start of the request that writes or reads it. A slow response uses part of that lifetime. Schedule a realistic test with the same generation lengths and pauses that the desk expects. Claude: when the cache lifetime starts

Separate a changed prefix from an unavailable entry

Claude cache diagnostics can compare consecutive requests using diagnostics.previous_message_id. It reports the earliest detected divergence, such as a changed system prompt or tools. The comparison describes request structure; usage.cache_read_input_tokens tells you whether input was actually read from cache. An inconclusive comparison is not evidence of a hit. Claude: diagnostics and actual cache reads

In the fictional desk, suppose a developer adds “current time” before the boundary. The stable-prefix fingerprint now changes on every request. Lengthening the lifetime would leave that defect in place. Move the changing value after the boundary, keep the same model and request configuration for the experiment, and rerun the paired requests.

If the reusable request matches and reads still disappear, investigate elapsed time and the chosen model’s cache requirements. Preserve the observed usage and diagnostics together. First requests and deliberately changed policy versions belong in a separate bucket from unexpected misses, or the dashboard will make normal cold starts look like regressions.

Review cost per completed case

A bounded pilot for the shipment assistant
TestRecordDecision it supports
Cold request followed by an identical reusable prefixWrite, read and uncached token countsDid caching occur?
Change only the shipment suffixRead count and source version in the answerCan current facts coexist with reuse?
Change the policy versionNew write and correct revised policyDoes freshness survive optimization?
Repeat with short and ten-minute gapsActual input charges and request-start timesWhich lifetime suits this workload?
Slow response or operator pauseObserved misses and completion latencyDoes the desk’s real timing match the model?

Compare equivalent completed cases: the same source evidence, accepted answer criteria and output limits. Include retries and requests that an operator rejects. A cheaper model call that creates more review work can increase the cost of resolving the shipment. Track correction time alongside the API charge, and keep the business-quality threshold unchanged between cache variants.

Start with one stable instruction bundle and one representative workflow. Use a full busy period that includes policy changes and quiet gaps. Select a cache lifetime from that trace, then repeat the comparison when the model or request layout changes. For cached answers stored by the application, review access revocation separately; prefix reuse and replaying a saved answer need different controls. Read: permissions and application answer caches

Putting this into practice?