How the numbers are worked out
Within one cache window, the first call writes the prefix to the cache at the cache-write price and every later call reads it at the cache-read price. New input and output tokens are billed normally on every call. Without caching, every call pays the full input price for the prefix as well.
Break-even is the number of calls per window at which caching starts to cost less than not caching. Because a cache write costs more than normal input, a prefix that is used only once costs a little more with caching. From the second call in the window it is almost always cheaper.
Getting a high hit rate
- Put stable content first. System prompt, tool definitions, then long documents, then the conversation, then the new question. The cache matches the prompt from the start, so anything that changes early breaks it for everything after.
- Keep tool order stable. Reordering or renaming tools between calls changes the prefix and turns every call into a cache write.
- Pick the lifetime for your traffic. If a user sends a message every few minutes, the 5-minute cache is enough. For prefixes shared across many users with gaps between calls, the 1-hour cache costs more to write but expires less often.
- Check the minimum length. Very short prefixes are not cached at all; see the official prompt caching docs for the current minimum per model.
More detail with code: Prompt caching in a Claude agent loop. Prices for every model: Claude API pricing.