← Claude & OpenAI Made Easy
18 min

Prompt Caching: Pay Less for Repeated Text

Reuse the start of a long prompt to save cost and time, and check that it works.

Lesson 5 of 11
0 done
In plain English

Prompt caching saves the start of a long prompt and reuses it. It is cheaper and often faster, and answers stay the same. Put stable text first and changing text last. The start must match exactly. The cache lasts minutes.

Cache hit
A request that reused the saved start.
Prefix
The beginning part of a prompt.
Cache write
Saving the start for later, at a small extra cost.
Picture it
Cache hit and cache miss
Cache hit
  • The start matches exactly
  • Reused copy is read
  • Cheaper and faster
Cache miss
  • Something at the start changed
  • Everything is read again
  • Costs the full price

Many AI apps send the same long text again and again. A company handbook. A set of rules. A long list of tools. Each time, the model must read it all from scratch. That costs money and time. Prompt caching fixes this. The provider saves the start of your prompt and reuses it. This lesson explains how it works in plain words.

The idea

  • The first request reads the long start and stores it. This write costs a little more than normal.
  • Later requests with the same start reuse the stored copy. Reading it costs much less.
  • Answers are the same as without caching. Only the processing changes.
  • Replies often come faster too, because the model skips the repeated work.

Order matters

The cache matches from the start of the prompt. So stable text goes first. Changing text goes last.

How to get hits

  • Keep the shared start word for word. Even a small edit makes a miss.
  • Do not put a date, a time or a random ID near the top. Put them at the end.
  • Mark where the stable part ends if the provider asks you to. Some tools can do this for you.
  • Keep your calls close together in time.

How long does the cache last

The Claude docs say the default is about five minutes. Each use refreshes the clock. A longer option exists for a higher write cost. Use it when users come back after a gap. Check the docs for the current numbers.

Limits to know

  • Very short prompts are not cached. There is a minimum length, and it varies by model.
  • Caches belong to one organisation. They are not shared.
  • Changing the tool list or some settings can clear the cache.
  • Two requests sent at the same moment may both miss. The cache is ready after the first reply starts.

Check that it works

Each response reports how many tokens were written to the cache and how many were read. If both are zero, your prompt was not cached. Look at that number in the first week.

cache-check.txt
Request 1:  cache written 4000 tokens, cache read 0       (first time)
Request 2:  cache written 0,    cache read 4000   (hit, cheaper)
Request 3:  cache written 4000, cache read 0       (miss: something changed)

When caching is worth the effort

Caching pays off when a long start repeats often. A support bot with a big handbook is a good fit. A tool that sends a long rule list with every call is another. A one-off question with a short prompt gains nothing. Measure before you invest. Look at how many tokens repeat and how often.

→If a long prompt starts with today's date, move the date to the end. That one change often turns misses into hits.
⚠Do not cache private data from one customer inside a shared prompt. Keep each customer's text out of the shared start.
Key takeaways
  • ✓Prompt caching reuses a saved copy of the start of a prompt. It is cheaper and faster.
  • ✓Put stable text first and changing text last.
  • ✓The shared start must match exactly, word for word.
  • ✓The cache lasts minutes. Each use refreshes it.
  • ✓Read the cache numbers in each response to confirm it works.
Hands-on exercise

Reorder a prompt for caching

  1. Take a prompt with a long rules section and a changing question.
  2. Move anything that changes, such as dates or names, to the end.
  3. List which parts are stable and which change.
  4. Write one sentence on what you would check in the response to see a cache hit.
Check yourself
Q1Why does a date at the top of a prompt hurt caching?show answer

The start changes every time, so it never matches the saved copy.

Q2Does caching change the answer?show answer

No. It changes how the input is processed, not what the model says.

Q3What shows that a request hit the cache?show answer

The response reports tokens read from the cache. If both numbers are zero, it was not cached.

← Structured Outputs and Tool CallsSkills: Teach AI Your Way of Working →
0 / 11 finished0%