Skip to content
mentoor

Topic 1 of 5 · 4 min read

Where provider prompt caching fits in the stack

Goal: For a given workload, decide whether provider prompt caching, a response cache or both apply, and estimate the saving.

Provider prompt caching makes a repeated prompt prefix cheaper and quicker to process, but the model still runs and still writes a fresh answer. A response cache skips the model entirely. Pick by what repeats: the start of the prompt, or the whole request.

Check yourself · 1 of 3

A provider prompt-cache hit happens on a request. What still runs?

Choose one answer

Why it matters

LLM bills and latency come from input tokens read and output tokens written. Many apps send the same 6,000-token system prompt, tool definitions and policy document on every call. Providers such as Anthropic (Claude) and OpenAI let you reuse the processed form of that shared prefix, so repeat calls cost less on those input tokens and start faster. Check each provider's pricing page for the current discount, because it differs by provider and changes.

How to decide

  1. List what repeats. Same prefix, different question: provider prompt caching. Same full request, same answer wanted: response cache. Neither repeats: no cache.
  2. Order the prompt for the prefix. Prefix matching means the stable part comes first (system prompt, tools, reference documents) and the changing part last (the user's message). One changing token early in the prompt, such as a timestamp in the system prompt, breaks the match for everything after it.
  3. Check the rules. Providers set a minimum prefix length, a short lifetime (minutes, refreshed on use) and, for some, an explicit marker you place on the prompt. Read the docs for the model you use.
  4. Estimate the saving. Saving is roughly: cached input tokens per call, times the share of calls that hit, times the price difference per token. It does not touch output tokens, which are often the larger cost.
  5. Measure hit rate per route. The API response reports cached and uncached input tokens. Log them per route and prompt version, and alert when a route's hit rate drops.

Before and after

Before: a support bot puts Current time: 14:03:22 on line one of its system prompt. Every request has a different prefix, so the hit rate is 0% even though the 5,000 tokens after it never change. After: the time moves into the final user message. The same 5,000 tokens now match on repeat calls.

What goes wrong

  • Expecting an answer cache. A prompt-cache hit still generates new output, so answers can differ and output cost stays.
  • Silent misses. A reordered tool list or a changed whitespace character ends the match. Without per-route hit-rate logging nobody notices the bill rising.
  • Low traffic. If the same prefix arrives less often than the cache lifetime, entries expire between calls and you pay write costs for nothing.

Examples

Order of a prompt

system: policy text (5,000 tokens, unchanged)
tools: 12 tool definitions (1,200 tokens, unchanged)
user: "Where is order 4471?"

The first two blocks form the shared prefix. Every customer question after them can reuse it. Putting the order number or the date above the policy text would make every request unique.

Two caches, two jobs

A help centre bot gets "How do I reset my password?" 400 times a day in near-identical wording, with a long system prompt. Provider prompt caching lowers the cost of the long prompt on all traffic. A response cache would remove the call altogether for the repeated question, but only if the answer is the same for every user.

Key points

  • Provider prompt caching reuses a repeated prefix but the model still runs; a response cache skips the call.
  • Put stable content first and anything that changes per request last, because matching is by prefix.
  • Savings apply to cached input tokens only; output tokens are billed as usual.
  • Entries are short-lived, so low-traffic routes can pay for writes and never get a read.
  • Log cached versus uncached input tokens per route and prompt version, and alert on drops.

Common mistakes

  • Treating a prompt-cache hit as if the answer was reused.
  • Putting a timestamp, request id or user name at the top of the system prompt.
  • Turning caching on without logging hit rate, then assuming it works.
  • Estimating savings on total tokens instead of cached input tokens only.

Check yourself · 2 of 3

A system prompt starts with the line "Today is 2026-12-02 14:03". Hit rate on the provider cache is near zero. What is the best fix?

Choose one answer

Check yourself · 3 of 3

Which metric tells you a route is actually benefiting from provider prompt caching?

Choose one answer

Practice items, not counted towards your mastery.

Start here