Prompt caching saves you severalfold, but it only works if the workflow architecture is built around it. The difference between cache-friendly and cache-blind automation is a bill that differs by multiples for the same volume of tasks. Here are the architectural patterns that make the cache your employee.
The principle: a stable head, a variable tail
Every request splits into a head (system prompt, rules, tools, files) and a tail (the question). The cache works when the head is byte-for-byte identical between requests. The workflow architecture therefore looks like this: everything constant goes into the head, everything variable goes into the tail. It sounds obvious, but in real pipelines the head “drifts”: timestamps, random identifiers, modified files — and the cache dies silently.
The technical trick: generate the head once and save it as a string; on every request, insert it unchanged. Any dynamic information goes into the tail. The check: in the usage field, the share of cached tokens on repeated requests should climb to stable values.
Patterns of cache-friendly workflows
- A batch of tasks with one head. Instead of “task → its own session” — “a batch of similar tasks with one head”: classifying a thousand emails runs with one head and a thousand short tails. The savings are multiplicative.
- Multi-step chains without reassembly. An agent chain (plan → execution → review) in one session with a fixed head instead of three separate calls with context reassembly. Code Mode reinforces the pattern: tools are invoked by code within a single session.
- File order is fixed. If files go into the head — their order is constant. “Re-read these files in a different order” = cache miss.
- Deferred dynamic data. Date/time, counters, random IDs — not in the head; put them in the tail or leave them out entirely.
Anti-patterns from practice
- Inserting the current date into the system prompt — every minute breaks the cache.
- Rebuilding the tool list from flags — one changed tool = a new head.
- Randomizing few-shot examples “for variety” — a death sentence for the cache.
- Alternating models within one workflow — each model has its own cache.
Measuring before and after
A case at scale: agentic video editing with 147 million session tokens, of which only 213,000 were written — 99% cache. Without the cache, such a workflow would have cost hundreds of times more. A second case: Code Mode cut task costs by 29%, partly thanks to batched calls with a cacheable head. You can audit your own workflow through the usage fields in the log: the accounting method is covered in the article about tokens.
Case study: overnight processing of support requests with a fixed head
Let us walk through a typical scenario in full. Every night the pipeline processes incoming requests: hundreds of short texts and one and the same instruction for all of them. A cache-blind setup creates a separate session for every request and inserts the current date straight into the system prompt — the head changes every few minutes, and every request pays for the full prompt all over again. A cache-friendly setup does it differently: the head with rules, categories, and the response format is assembled once when the pipeline starts and stored in a variable, while the request number and the email text go into the tail.
# the head is assembled once when the pipeline starts
HEAD = ("You are a request classifier. Rules: ...\n"
"Categories: billing, bug, feature, other\n"
"Response format: category — one sentence")
# on every request the head is inserted unchanged
payload = {
"system": HEAD,
"messages": [{"role": "user",
"content": f"Request #{ticket_id}:\n{ticket_text}"}],
}After the batch has run, open the log and look at the usage field: the share of cached tokens should rise from the second request and hold at stable values until the end of the batch. If cached tokens are zero on every request — dynamics have leaked into the head: a date, a counter, a rebuilt tool list, or a file modified between requests. Run through the anti-pattern list above — the culprit is usually found within a couple of minutes.
Such a case is a minimal unit that transfers easily to another pipeline: classification, field extraction, labeling, generation of short template-based replies. The rule is one: nothing that changes between requests is inserted into HEAD — not even “useful” information such as the launch time or the run number. All of it moves into the tail or stays in the log, not in the prompt. When the pipeline grows and sub-agents appear, the same principle carries over to them: each sub-agent gets its own fixed head, and a batch of sub-agents with the same head is cached as a single batch of tasks.
Common questions
Does the cache work between workflow runs? Within the cache’s lifetime (about 5 hours for Claude) — yes, if the head is identical: overnight batches with the same head continue on the morning’s cache.
Do all providers cache? The major ones — yes, the mechanics are similar; “gray” gateways — check via usage. On free tiers the cache also saves token quotas.
Is the cache compatible with sub-agent roles? Yes: a sub-agent with a stable head gets cached on its own; a batch of sub-agents with the same head — multiplicative savings.
What if the rules change often? Rare rule edits are not an anti-pattern: one cache miss after an edit pays for itself with stability afterward. The anti-pattern is edits on every request.
How do I make sure the cache is working? Look at the usage field on repeated requests: the share of cached tokens should grow and settle at stable values. Zero on every request — the head is “drifting”, look for dynamics in the system prompt.
Is it worth caching short heads? The benefit is noticeable when the head makes up a significant part of the request: rules, tools, files. If the system prompt is a couple of lines and the tail is long, the savings will be modest, and the time spent debugging the head will not pay off.
Do I need to clear the cache between tasks? No: the cache requires no reset, it simply expires with time. A miss is not penalized separately — a request that misses costs exactly what it would cost without any cache at all.
Do temperature and other generation parameters affect the cache? No: the cache is matched against input tokens, not against the model’s answer. Sampling parameters have no effect on whether the head hits — only the byte-level identity of the head between requests matters.
Cache-friendliness is a property of the architecture, not a checkbox in the settings: a fixed head, batched tasks, a fixed file order. Build it that way — and the bill shrinks on its own. Practice as of fall 2026.
