Prompt caching explained: what it saves and how to structure prompts for it

Updated · 5 min read

What the provider actually stores

Caching works on the prefix of a prompt, meaning the part at the beginning that stays the same from one request to the next. The provider can reuse the processed form of that prefix only if the new request matches it exactly, from the first character up to the point where caching applies. Anything that changes early in the prompt breaks the match for everything after it.

Providers differ in how you turn it on. Some cache automatically once a prompt is long enough, while others need you to mark which part to cache. Each cached entry also expires after a period set by the provider, so requests that arrive far apart may never reuse it.

Which parts of a prompt benefit

Caching pays off when a large block of text is repeated across many requests. Typical candidates are:

  • Long, fixed system instructions that define the role, the rules and the output format.
  • Reference documents that many questions draw on, such as a product catalogue or a policy handbook.
  • Tool definitions and output schemas that do not change between calls.
  • A set of worked examples that you use in every request.
  • Not the latest user message, the current date, a customer ID or any other value that changes every time.

How caching changes cost and speed

Cached input is usually billed at a lower rate than fresh input, but the first request that writes the cache may cost more than a normal one. The saving therefore depends on how often the same prefix is reused before it expires. A prefix used once saves nothing, and one used many times can save a great deal.

Caching can also reduce the time before the first word of a reply appears, because the model does less work on the repeated prefix. The gain is most noticeable on long prompts. Read the current pricing and latency notes in your provider's documentation, and measure the difference on your own traffic rather than assuming it.

How to structure a prompt so the cache is reused

Layout matters more than the feature switch. Arrange every prompt in the same order, with the stable material first and the changing material last.

  • Put the tool definitions and system instructions first, then any reference documents. Check the order your provider caches in, since Anthropic builds its cached prefix as tools, then system, then messages.
  • Put the user's question, the date, the customer ID and other variable values at the end.
  • Keep the static text identical, character for character. Do not insert timestamps, random IDs or reordered examples into it.
  • Group requests that share a prefix so they arrive close together, within the cache lifetime.
  • Log the cached token counts that the provider returns with each response, so you can see the hit rate rather than guess it.

Mistakes that defeat the cache

Most caching disappointments come from a small change at the top of the prompt. Check for these before you judge the feature.

  • Placing today's date or a session identifier at the start of the system prompt.
  • Rebuilding the instructions from a template that fills in a variable in the middle, so the text drifts between requests.
  • Changing whitespace or line breaks between versions without noticing.
  • Sending a few short requests spread over a long period, so the cache always expires first.
  • Assuming the cache is working without reading the usage data that shows it.

How Hundred Seas helps

Hundred Seas builds AI agents and AI CRM systems on Claude and on OpenAI models. Because each provider sets its own caching rules and prices, we take those rules into account when we choose a model for a task, along with cost, speed, quality and where the client's data has to stay. We are a registered partner in Anthropic's Claude Partner Network and an OpenAI partner.

A scope step of about one week, at a fixed price, ends in a written plan and a firm quote. The build follows in two to four weeks of weekly releases, and a monthly run plan keeps the software current when provider rules change.

Questions

Is prompt caching the same as storing answers?
No. Prompt caching stores the processed form of the start of a prompt, not the answer. The model still writes a new response each time. To reuse answers, you need a cache in your own application, with rules about when an answer is too old to reuse.
Does caching change what the model answers?
It is meant to be a speed and cost feature, not a change to the instructions the model reads. Even so, test your outputs after you turn it on, because a small change in prompt layout can alter the text you send, and you want to confirm nothing else moved.
How long is a cached prefix kept?
The lifetime is set by each provider and can differ between features. Read the current documentation for the exact rule. If your traffic is sparse, the cache may expire between requests, and the saving can be small. Busy features with steady traffic usually benefit most.
Does caching help a short prompt?
Usually very little. Caching matters most for long, repeated prefixes, and many providers apply it only above a minimum size. For short prompts, the better step is to shorten the instructions and send less context, which helps every request.
Is cached content safe to use with customer data?
Cached content is held by the provider under its data terms, so check how long it is kept and how your account data is used. Keep personal data out of any prefix you share across customers, and put customer-specific values at the end of the prompt where they are not part of the cached block.

Have a project in mind?

Tell us what you want to build. We reply with a plan, not a sales call.

AboutPrompt caching explained: what it saves and how to structure prompts for it