Let's talk.

Whether it's a project, a role, or you just want to say hi, my inbox is open.

kadhar.mfn@gmail.com
AboutExperienceProjectsWritingResearchFree guidesFree ebookToolsGames

© 2026 Kadharmoideen Fadurudeen. Made with care.

kadhar.
AboutExperienceProjectsWritingResearchFree guides
Tools
Say hello
Back to Blog
AI Engineering
December 2, 2026
9 min read

Prompt Caching Explained: Cut Your LLM Bill by Reordering Your Prompt

How prompt caching works in Claude, OpenAI and Gemini, the one rule that decides whether you get cache hits, the quiet mistakes that break it, and what it does to a real bill. With an interactive prompt-order demo.

Look at what your app actually sends to the model. Most of it is the same every single time.

The system prompt, the tool definitions, the product docs you paste in for context. That's often thousands of tokens, and only the last little bit, the user's question, is new. Without caching, you pay full price to process all of it again on every request.

Prompt caching fixes that, and it's one of the few cost tricks that doesn't make anything worse. The answers are identical, responses come back faster, and the bill drops. But it only works if you build your prompts in a particular way, and it's easy to break without noticing.

How it works, without the jargon

Before a model can answer, it has to read your whole prompt and turn it into its internal working state. That reading step is what you pay for as input tokens.

With caching, the provider keeps that working state for a short while. If the next request starts with exactly the same text, it picks up from the saved state and only reads the new part at the end.

The important word is starts. The cache matches from the beginning of the prompt, token by token, and stops at the first difference. Everything after that point is processed again at full price, even if it's identical to last time. One changed word near the top, and nothing below it is cached.

The one rule: static first, dynamic last

So the whole game is ordering. Put the parts that never change at the top, the parts that change sometimes in the middle, and the parts that change every request at the very end.

Try it below. The starting order is a very common one: a friendly “Today is Tuesday, you're helping Priya” line at the top, then everything else. It looks harmless, and it means nothing gets cached.

Top of the list is the start of the prompt. Move the parts around and watch what the cache can reuse.

  1. Today's date and the user's name

    50 tokens · changes every request · full price

  2. Tool definitions

    800 tokens · same every time · full price

  3. System instructions

    1,500 tokens · same every time · full price

  4. Product docs

    2,700 tokens · same every time · full price

  5. The user's question

    150 tokens · changes every request · full price

Prompt reused from cache

0%

Monthly cost, no cache

$4,020

Monthly cost, this order

$4,020

Claude Sonnet 5.5 list prices, 10,000 requests a day, 300 output tokens each. Cache-write fees are left out; with steady traffic they add only a few dollars a day.

Moving one short line from the top to the bottom takes the monthly cost from about $4,020 to about $1,170 in this example. Notice what's left once caching is working: most of the remaining bill is output tokens. Caching only ever helps the input side, so it pairs well with keeping answers short.

How Claude, OpenAI and Gemini differ

The idea is the same everywhere. The details aren't, and they matter when you're choosing a provider or debugging a low hit rate. This is from each provider's official docs as of December 2026.

Claude

Turning it on:
Add cache_control at the top level of the request, or on up to 4 specific blocks.
Minimum prompt:
512 tokens on current models
How long it lasts:
5 minutes by default, or 1 hour
Writing to cache:
1.25× input price (5 min), 2× (1 hour)
Reading from cache:
0.1× input, 0.05× on Opus and Sonnet 5.5, 0.025× on Fable

OpenAI

Turning it on:
On by default. Explicit breakpoints are optional if you want control.
Minimum prompt:
1,024 tokens
How long it lasts:
30 minutes by default, or 12 hours
Writing to cache:
1.25× input price (30 min), 2.5× (12 hours)
Reading from cache:
0.1× input, 0.05× on GPT-6.1 and 6.2

Gemini

Turning it on:
Implicit caching is on by default. Explicit caches are also available.
Minimum prompt:
4,096 tokens on Gemini 4
How long it lasts:
Best effort, up to 24 hours
Writing to cache:
No write or storage fee for implicit caching
Reading from cache:
0.05× input on Gemini 4
ClaudeOpenAIGemini
Turning it onAdd cache_control at the top level of the request, or on up to 4 specific blocks.On by default. Explicit breakpoints are optional if you want control.Implicit caching is on by default. Explicit caches are also available.
Minimum prompt512 tokens on current models1,024 tokens4,096 tokens on Gemini 4
How long it lasts5 minutes by default, or 1 hour30 minutes by default, or 12 hoursBest effort, up to 24 hours
Writing to cache1.25× input price (5 min), 2× (1 hour)1.25× input price (30 min), 2.5× (12 hours)No write or storage fee for implicit caching
Reading from cache0.1× input, 0.05× on Opus and Sonnet 5.5, 0.025× on Fable0.1× input, 0.05× on GPT-6.1 and 6.20.05× input on Gemini 4

A few things worth pulling out of that table:

  • Writing to the cache can cost extra. On Claude and OpenAI, the first request that stores the prefix pays a bit more than normal. If a prefix is only ever used once, caching it costs you money. It pays off from the second hit.
  • Minimums are real. A 600-token prompt is cacheable on Claude but not on OpenAI or Gemini. Below the minimum, nothing fails. You just quietly pay full price.
  • Lifetimes are short by default. Five minutes on Claude, thirty on OpenAI. Steady traffic keeps the cache warm. A request every twenty minutes may miss it every time, so the longer option is worth it there.

On Claude, it's one line

Claude needs you to ask for caching. The simplest way is a single cache_control at the top level of the request, which caches everything up to the last block it can:

const response = await client.messages.create({
  model: "claude-sonnet-5-5",
  max_tokens: 1024,
  cache_control: { type: "ephemeral" },
  system: SYSTEM_PROMPT + PRODUCT_DOCS, // the same every time
  messages: [
    { role: "user", content: `Today is ${today}. ${question}` }, // changes
  ],
})

Notice where the date went: into the user message at the end, not the system prompt. If you need finer control, for example tools that never change and docs that change weekly, you can place up to four breakpoints on individual blocks instead.

The quiet cache-busters

When the hit rate is low, it's almost always one of these. None of them throw an error. The bill is just higher than it should be.

A timestamp in the system prompt

Even a date changes once a day. With the time in it, it changes every request.

Personal details up top

“You're helping Priya.” Every user gets their own prefix, so nobody shares a cache.

Tools in a different order

Building the tool list from a set or a map can shuffle it. Different order, different prefix.

JSON that doesn't serialise the same way

Keys in a different order or different spacing look identical to you and different to the cache.

Changing settings between calls

Switching tools, tool choice, thinking or effort settings can reset part or all of the cache.

A/B testing the system prompt

Two variants means two caches, each warm half as often.

Measure it, don't assume it

Every provider tells you how many tokens came from the cache in the usage part of each response. On Claude it's cache_read_input_tokens (and cache_creation_input_tokens for writes). On OpenAI it's usage.input_tokens_details.cached_tokens. Gemini reports cached tokens in its usage metadata too.

Log it next to total input tokens and track the ratio. Cached tokens divided by input tokens is your hit rate. It's the most useful single number here, because it catches regressions. Someone adds a timestamp to the system prompt on a Friday, the ratio drops from 80% to nearly zero, and you find out from the dashboard instead of the invoice.

When caching won't help much

  • • Short prompts under the provider's minimum.
  • • Every prompt is genuinely different, like summarising a new document each time.
  • • Low, spiky traffic where the cache expires between requests.
  • • Costs dominated by output, like long generated reports. Caching doesn't touch output.

For the last two, the batch APIs are the better lever: all three providers charge half price for work that can wait.

Frequently Asked Questions

What is prompt caching?

When many requests start with the same text, the provider keeps the processed version of that opening part for a while. The next request that starts the same way reuses it, which is faster and much cheaper than processing it again.

How much does prompt caching save?

Cached input costs between 2.5% and 10% of the normal input price, depending on the provider and model. If most of each prompt is the same instructions, tools or documents, input costs typically drop by well over half. Output tokens are never cached, so they set the floor.

Is prompt caching automatic?

On OpenAI and Gemini it's on by default for current models. On Claude you turn it on with cache_control, either once at the top level of the request or on specific blocks. In all three, you only get hits if the start of the prompt stays exactly the same.

Why am I getting no cache hits?

Usually something near the top of the prompt changes every request: a timestamp, the user's name, a request ID, tools in a different order, or a different setting. The prompt may also be shorter than the minimum the provider will cache, or the requests may be too far apart for the cache to still be there.

Does prompt caching change the model's answers?

No. A cache hit gives the same result as processing the prompt from scratch. It only changes speed and price.

The short version

Put what never changes at the top of the prompt and what changes every time at the bottom. Keep tools, settings and serialisation stable. Turn caching on if you're on Claude, and log the cached-token ratio wherever you are. To see what it does to your own numbers, try the LLM cost calculator, which has a setting for how much of each prompt is cached. If you're still picking a model, this guide to choosing one covers the rest of the bill.

PreviousIEEE Senior Member: What It Is, Who Qualifies and How to ApplyNextRAG from Scratch: Chunking, Embeddings, Retrieval and Why It Fails

Continue Reading

Explore more articles on software engineering and technology

AI Engineering

Making AI Features Feel Fast: Streaming, Latency and UX

Time to first token vs output speed, streaming from the model to the browser in Next.js, the UX details that make streaming feel polished, and the changes that genuinely cut latency. With an interactive race between waiting and streaming.

11 min read
Read
AI Engineering

Prompt Injection and AI Security: A Practical Guide for App Developers

Why LLMs can't reliably tell instructions from data, how indirect injection hides in emails and web pages, the lethal trifecta, and the layered defences that hold: fewer capabilities, real confirmation, output control, quarantine and testing. With an interactive attack demo.

13 min read
Read
AI Engineering

Structured Output and Tool Calling: Getting Reliable JSON from LLMs

Prompt-only vs JSON mode vs structured outputs, how Claude, OpenAI and Gemini do it, schema design that helps the model, the validation you still need, and how tool calling works under the hood. With an interactive demo of what each layer catches.

12 min read
Read