Cortex Reply

Prompt caching in agentic systems: cut the cost of every loop

Leo Messen8 min read

Abstract illustration of stacked green layers with a looping arc passing over them, representing a cached prompt reused across agent loops
Contents

Save up to 80 per cent on your agent costs with prompt caching.

Caching stores the start of your prompt, so every later call reads it back at a fraction of the price. Any agent that calls a tool and reasons on the result is cheaper from its second call, and the right prompt structure keeps it that way.

Every time an agent calls a large language model (LLM), it sends the whole prompt: tool definitions, system prompt, a skills list, the conversation so far and the results of any tools it has run. An agent also works in a loop, calling the model, running the tools the model asks for and calling the model again until the task is done. A task with six passes therefore processes much of the same prompt six times.

Prompt caching removes the repeat. The provider stores its work on the start of your prompt, and later calls read it back at a fraction of the price. This article covers how caching is priced, why it's essential for agents and how to structure a prompt to get cache hits with the associated cost savings.

How prompt caching works

A provider can keep the work it has done on the start of a prompt. If your next request begins with identical content, up to a marker called a cache point, the provider reads that work from the cache instead of processing it again. The call costs less and returns sooner. The match is exact, character for character, so one change near the start sends everything after it back to full price.

The reuse is not limited to one conversation. Any request in your account or workspace that starts with the same content reads the same cache entry. An agent used by many people, or across many sessions, therefore hits the cache on everything that stays the same between interactions: the tool definitions, the system prompt and, within a conversation, every earlier message up to the new user message.

The price structure rewards reuse. On Claude models, writing to the cache costs 1.25 times the normal input price for a five-minute cache lifetime, or twice for one hour. Reading costs a tenth on most models, and as little as 2.5 per cent on the newest. Other providers set their own prices, but they all offer massive savings on input tokens.

Why every agent should use it

The write premium is the only extra cost, and one reuse repays it. Call the normal price of the start of the prompt one unit. A task with two model calls, one tool call followed by the model reasoning on the result, costs two units uncached. Cached, it costs 1.35: 1.25 for the write and 0.1 for the read. Every further pass widens the gap.

Any agent that calls a tool and reasons on its output is therefore always going to be cheaper with caching. Only a single model call with no follow-up costs more, which for any capable agent is very rarely the case. The units cover only the start of the prompt. As the loop runs, each tool result and each reply the model writes joins the cache on the next pass and is read back at the discount on the passes after that.

Here is an example from one real turn of one of our agents. The agent ran on Claude Sonnet 5.5 and went round the loop three times, making two tool calls. It sent about 79,000 input tokens across the three model calls, and caching served 65 per cent of them. This was a cold start, so the first call had to write its 25,291-token prompt to the cache. Even so, the turn cost $0.09 against about $0.17 without caching, a saving of 46 per cent.

The cold start is the most expensive part, and it only happens when the cache is empty. Any request that begins with the same prompt, from any user, can read that start from the cache. Here, about 90 per cent of the prompt is the definitions of the agent's tools, which every request shares. Run the same turn again with a warm cache and the first call reads its prompt instead of writing it, so the turn costs about $0.035. That is 80 per cent less than without caching and 62 per cent less than the cold turn. A saving of $0.14 is not much for one turn but a system with many users, and many interactions, keeps its cache warm, so most of its turns cost like the second one. At only 1,000 interactions a day, that is about $140 saved a day, or roughly $4,200 a month.

Cost is also what usually limits which model an agent can use. Better models cost more per token, and an agent that loops many times can run up a large bill on one without caching. You should still rightsize your models, but when a task genuinely benefits from a larger model, that is where caching saves the most money in absolute terms, because the discount applies to the highest prices. You compromise less on capability for the sake of cost.

Structure your prompt for cache hits

Order the prompt from most stable to least stable. Tool definitions come first, then the system prompt with its instructions and skills list, then the conversation, with a cache point after each layer. Anything that changes between calls, such as the date and time, a request id or a counter, goes after the last cache point. You pay full price for those few tokens and still cache everything before them.

Three mistakes break this without raising an error. A changing value at the front of the prompt gives every call a new start. A tool list built from something with no fixed order, such as a set in Python, comes out differently in each process and splits the cache. Content that updates inside the cached start, such as a skills list or running notes, forces a rewrite on every call. The agent still answers correctly and only the bill rises, so record tokens read, tokens written and tokens saved on every turn, and check them after any change to a prompt, tool or framework. Test through the path your agent really uses, because tests that call internal methods miss these bugs.

Five minutes or one hour

Providers usually offer more than one option for cache lifetimes. Every cache hit refreshes the lifetime at no extra charge, so a five-minute cache lasts as long as calls arrive less than five minutes apart. An agent that loops every few seconds, or a conversation where the user replies within minutes, pays the write once and reads for the rest of the session. For that pattern five minutes is always cheaper, because the one-hour write costs twice the normal price and adds nothing.

A gap changes the answer. If nothing arrives for five minutes, the cache expires and the next call pays the write again instead of a read, about 1.15 units more than a hit. The one-hour write costs only 0.75 units more than a five-minute write, so a fill that would otherwise expire even once is cheaper on one hour. That suits agents that wait for a person to approve an action, run slow tools or sit idle between users.

Frequently asked questions about prompt caching

What is prompt caching?

Prompt caching lets a model provider store its work on the start of a prompt, so later requests that begin the same way skip it and cost less. The model sees the same prompt, so its answers do not change.

How much does prompt caching save?

On the repeated part of a prompt, up to 90 per cent on most Claude models and up to 97.5 per cent on the newest, because reads cost a tenth or less of the normal input price. Across a whole turn it is lower, because output tokens are never discounted. In one real agent turn, caching cut the cost by 46 per cent on a cold start and about 80 per cent once the cache was warm.

How does prompt caching work across users and sessions?

Cache entries are not tied to a user or a session. Any request in the same account or workspace that starts with the same content reads the same entry. An agent with many users and sessions therefore hits the cache on its tool definitions, its system prompt and, within a conversation, every earlier message. In one of our agents, about 90 per cent of the prompt was tool definitions that every request shares. Caches are never shared across organisations, even for identical prompts.

How long does a cached prompt last?

On Claude models, five minutes or one hour, and every hit refreshes the lifetime at no extra charge. Use five minutes when calls arrive less than five minutes apart. Use one hour when the agent often pauses for longer, for example while it waits for a person to approve an action.

Why am I not getting cache hits?

Something at the start of the prompt is changing, or the prompt is too short. The usual causes are a date or timestamp near the front, tool definitions in a different order on each request, content such as a skills list that updates between calls, and a prompt below the model's minimum cacheable size. Check the cache read and write counts in each model response. If reads stay at zero on repeated requests, one of these is the likeliest cause.

Is caching worth it if my agent only loops twice?

Yes. Writing to the cache costs 25 per cent more than normal input and each read costs a tenth or less, so a second call already recovers the extra cost. Over two calls, the repeated start of the prompt costs about a third less than without caching.

Which providers and models support prompt caching?

The main model providers all support it. Every active Claude model supports caching, through Anthropic's own API and through Amazon Bedrock, Google Cloud and Microsoft Foundry. OpenAI caches prompts of 1,024 tokens or more automatically. Google's Gemini models cache automatically and also offer explicit caching. Minimum prompt sizes, lifetimes and prices differ by provider and model, so check your provider's documentation before you forecast savings.


Cortex Reply builds production AI systems for enterprise. If you want to talk about the cost of running agents at scale, get in touch.

Talk to us and build something amazing.