- message
- Order 88231 never arrived. Can I have my money back?
- system prompt
- 2,140 tokens: role, refund rules, tone
- tools
- 5 cards, 880 tokens
- cache_read_input_tokens
- 3,020 (tools and system prompt) (new)
- input_tokens
- 19 (the new message) (new)
Step 1 · Sent
The request goes out as tokens, most of them from the cache
The customer types one line. The model receives far more: the shop's system promptSystem PromptInstructions the builder of an AI app gives the model before you type anything. It sets the role, the tone and the rules, and it outranks what users say. with its rules, a card for each of the agent's 5 tools, and then the message. All of it is counted in tokensTokenThe small piece of text a language model reads and writes, often part of a word. Prices, limits and the context window are all counted in tokens.. The tools and the system prompt are the same for every customer, so the app marks the end of the system prompt for prompt cachingKV CacheWork a model saves from the text it has already read, so it is not redone for every new token. Prompt caching keeps that work between requests and charges less for it.. The next request that starts the same way reads that part from the cache, for a tenth of the normal input price or less, and the model only has to process the new message.
What goes wrong
The cache only matches a start that is identical, byte for byte. Put the time or the customer's name near the top of the system prompt and every request starts differently, so the app pays to write the cache each time and never reads it. A cached entry also lasts 5 minutes by default, refreshed each time it is used.
On the Claude APIPrompt cachingToken counting
{
"model": "claude-sonnet-5-5",
"max_tokens": 4096,
"tools": [ look_up_order, track_parcel, search_policy, issue_refund, memory ],
"system": [{
"type": "text",
"text": "You are the support agent for the shop. Refund rules: ...",
"cache_control": {"type": "ephemeral"}
}],
"messages": [{"role": "user", "content": "Order 88231 never arrived. ..."}]
}