Enclave, an events and membership platform, has an in-app AI assistant. Staff ask it to find attendees, update events or check people in. The assistant is an agent: it calls a tool, reads the result and decides the next step. One request often takes several model calls.
Every one of those calls sent the same large prompt again: the rules, the tool definitions and their schemas. That prefix was about 17,000 tokens. The part that changed per call was small. We paid full price for the same text, many times per request.
Prompt caching fixes exactly this. The provider stores the start of your prompt, and the next call that begins with the same text reads it from the cache at a much lower price. It sounds like a one-line setting. In practice, three decisions decided whether it worked.
1. Mark what to cache
Anthropic models cache only what you mark. We added two markers: one on the request, and one on the first system message, which holds the static rules. The code wraps the HTTP client, so no feature code had to change.
export function addPromptCache(body: string): string {
let parsed: unknown;
try {
parsed = JSON.parse(body);
} catch {
return body;
}
if (
!isRecord(parsed) ||
typeof parsed.model !== 'string' ||
!parsed.model.startsWith(CACHED_MODEL_PREFIX) ||
'cache_control' in parsed
) {
return body;
}
const messages = Array.isArray(parsed.messages)
? markStaticPrefix(parsed.messages)
: parsed.messages;
return JSON.stringify({
...parsed,
messages,
cache_control: { type: 'ephemeral' }
});
} If the body is not valid JSON, or the model is not an Anthropic model, the request goes out unchanged. A caching helper must never be the reason a call fails.
2. Put static text first and per-request text last
A cache matches from the start of the prompt. One changed character early in the prompt makes everything after it a cache miss.
Our first prompt put the organisation’s name and today’s date before the static rules. So the text that changed per organisation and per day sat in front of the text that never changed. We moved it to the end: rules first, tool definitions next, organisation and date last.
Now every organisation shares one cache entry. When a second organisation sent its first request, it read 17,088 of its 17,217 input tokens from the cache. That first call was 91% cheaper than before.
3. Keep the tool list stable
We had a plan to send only the tools that seemed relevant to each step. A smaller list looks cheaper. We rejected it, because tool definitions are part of the cached prefix. A different tool list on each step invalidates the cache every time. A stable list of all tools, read from the cache, costs less than a short list that is never cached.
The result
| No caching | First setup | Final setup | |
|---|---|---|---|
| Share of input read from cache | 0% | 53% | 92% |
| Cost of one 30-case run | $0.118 | $0.077 | $0.025 |
Per model call, the cost fell from $0.00183 to $0.00038 (−79%). Billed input tokens fell by 82%. Latency also improved, because cached tokens are processed faster: the median call went from 5.2 s to 4.1 s.
The assistant has a hard budget of $5 per organisation per month. Before caching, that paid for about 2,700 model calls. After caching, it pays for about 13,000.
When caching does nothing
On a different project, a translation feature on an EU platform, caching did not work at all. The usage data showed cache_read: 0 on every call. The reason: the static prefix was about 1,321 tokens, and that model, Claude Haiku 4.5, only caches prompts of 4,096 tokens or more. The marker was there, but nothing was long enough to cache. Check the minimum length for your model before you count on a saving.
The document extraction feature on the same platform taught us a second rule. Parallel requests cannot read a cache entry that is still being written. So the pipeline sends the first chunk of a document alone to warm the cache, and only then sends the rest, 5 at a time.
Our internal budget estimate ignored the cache discount, so it counted costs about 5 times too high. If your cost meter uses list prices for all input tokens, it will tell you that caching saved nothing. Use the provider’s reported cost, or apply the cache price.
What to copy
- Mark the cache explicitly if your provider needs it, and do it in one place, such as the HTTP client.
- Order the prompt from most stable to least stable. Rules and tools first. Names, dates and user data last.
- Do not change the tool list per step. A stable, cached list is cheaper than a short, uncached one.
- Check the minimum cacheable length for your model, and look for
cache_readin the usage data to prove that caching works.
Caching works best after you have chosen the right model. For how we picked that model, read we compared 23 LLMs on our own evals. If your AI bill grows faster than your usage, see how we cut LLM cost.