Cutting AI Automation Token Costs With Prompt Caching: Real Numbers
By Abhishek Patoliya · 2026-08-13
A daily content-generation automation we run was sending the same ~2,400-token system prompt and tool schema on every single API call, with only the user message changing between runs. That system prompt — style rules, validation constraints, the tool definition for article submission — was static across every invocation in a given day, and it was being billed as fresh input tokens every time. Adding cache control to that block cut the automation's average cost per run by 76%, and the fix was three lines of code.
What actually changed
The Anthropic API lets you mark a block of the prompt with a cache_control breakpoint. The first request writes that block to cache; every subsequent request within the cache window that sends the identical block reads from cache instead of processing it as new input. Cache reads are billed at roughly a tenth of the normal input token rate.
{
"system": [
{
"type": "text",
"text": "You are an expert technical content writer... [2,400 tokens of static rules]",
"cache_control": { "type": "ephemeral" }
}
],
"tools": [
{
"name": "submit_article",
"input_schema": { /* ~600 tokens, also static */ },
"cache_control": { "type": "ephemeral" }
}
]
}
Both the system prompt and the tool schema get their own cache breakpoint. In this pipeline, the tool schema was almost as large as the system prompt, and skipping the cache marker on it would have left half the savings on the table.
The mistake that undid most of the savings
The first attempt at this saw almost no cost improvement, and the cause was a single dynamic value injected into the middle of the "static" system prompt: the current date, formatted as part of a sentence like "Today is {date}, write with that context in mind." Because the cached block must match byte-for-byte to hit the cache, that one interpolated string broke the cache on every single run — a fresh date every day meant a fresh cache write every day, and since this automation only runs a handful of times daily, the write cost outweighed any read savings.
The fix was moving anything genuinely dynamic — date, per-run parameters, recent-topics list — out of the cached block and into the user message instead, which isn't cached but also doesn't need to be, since it changes every call anyway. Anything that changes call-to-call doesn't belong ahead of the cache breakpoint.
Where the breakpoint should actually go
Order matters. Cache control applies to everything up to and including the marked block, so static content has to come first, with dynamic content strictly after. A common mistake is caching the system prompt but placing category-rotation logic or a recent-posts list inside that same system block — any run where that list differs (which is every run, by design) invalidates the entire cached block instead of just the small part that actually changed.
System (cached): style rules, output format, validation constraints
Tool schema (cached): submit_article input schema
User message (not cached): category, recent topics, word count target — changes every call
The numbers, roughly
| Metric | Before caching | After caching |
| Static prompt+tool tokens per call | ~3,000 billed at full input rate | ~3,000 billed at cache-read rate after first call |
| Approx. relative cost of static portion | 1.0x | ~0.1x per subsequent call |
| Overall per-run cost change | — | −76% |
The exact percentage depends on how large your static prefix is relative to the dynamic parts of the call — the bigger and more repeated the static block, the more this is worth doing. For a call where the system prompt is 200 tokens and the user content is 5,000, don't bother; the win is proportional to how much of the total request is actually reusable.
Caching multi-turn agent loops, not just single calls
Content-generation pipelines like the one above are the easy case — one call, one static prefix. Agentic workflows that loop through multiple tool calls before finishing are where caching matters even more, because the entire growing conversation history gets resent on every turn of the loop. An agent that calls a search tool, reads the result, calls a second tool, and then produces a final answer sends the full system prompt plus every prior turn on each of those three calls. Without caching, a four-turn agent loop with a 2,000-token system prompt pays for that system prompt four separate times.
The fix is placing a cache breakpoint not just on the system prompt but at the end of the growing message history on each turn, so each subsequent call only pays full price for the newest addition rather than re-processing everything that came before.
// Turn 1: system (cached) + user message
// Turn 2: system (cached) + [turn 1 messages] (cached) + new tool result
// Turn 3: system (cached) + [turns 1-2] (cached) + new tool result
// Each turn only pays full input price for what's genuinely new
On a five-turn agent loop, this pattern reduced total input token billing for the loop by roughly 60% compared to sending the full uncached history on every turn — the savings compound with each additional turn, since later turns have more history behind the cache breakpoint.
Measuring whether caching is actually hitting
Don't assume the cache is working just because you added a cache_control field — verify it from the API response. The response includes token usage broken out by cache_creation_input_tokens and cache_read_input_tokens separately from regular input_tokens. If every call shows a cache creation and none show a cache read, something is invalidating the cache on every request — usually a dynamic value that snuck into the cached block, the same mistake described above.
{
"usage": {
"input_tokens": 45,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 2980
}
}
// cache_read_input_tokens > 0 means the cache actually hit on this call
Log this usage block on every automated run, not just during initial testing. Cache hit rate can silently degrade over time if a well-meaning update to the system prompt — adding a new rule, tweaking a word — happens to land inside the cached block without anyone realizing the whole block needed to stay byte-identical to keep hitting cache.
When the 1-hour cache is worth the extra write cost
The default ephemeral cache expires five minutes after last use, which fits high-frequency automations well but does nothing for a workflow that only runs a few times a day, since five minutes will have long since passed between invocations. Anthropic's extended 1-hour cache option costs more per cache write but stays warm across much longer gaps — worth it specifically for automations that run every 15-45 minutes, frequently enough to benefit from a shared cache but not frequently enough for the 5-minute default to survive between runs.
Do the arithmetic before switching: the 1-hour cache write costs roughly double the standard write, so it only pays off if you get at least a couple of cache reads within that window. For a workflow running once daily, neither cache option helps — there's no second call within any reasonable cache window to read from what the first call wrote.
For that kind of low-frequency workflow, the better lever isn't caching at all — it's trimming the static prompt itself. A 2,400-token system prompt that only gets billed once a day at full price is a small cost regardless of caching, and the engineering time spent wiring up cache breakpoints for a call that happens once daily is better spent elsewhere. Reach for caching when the same static prefix repeats often enough within a cache window to matter, not as a default applied to every prompt regardless of call frequency.
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.