Zenaique

Your team is paying $40k/month on LLM tokens: most calls share a long system prompt + 8k tokens of few-shot examples. How does prompt caching help and what's the expected savings?

Short answer·Medium·4.0 · 0·~3 min·Asked atAnthropicDoordashOpenAI
Attempt it

You're an MLOps engineer reviewing a $40k/month LLM token bill. Most calls share the same system prompt (~500 tokens) + ~8k tokens of stable few-shot examples + ~2k tokens of per query content. Explain how prompt caching works, what specifically becomes cacheable, the expected savings, and at least one operational gotcha that could prevent realizing them.

Free · 2 AI evals / day
TL;DR

Cache the 8.5k stable prefix at one-tenth input price; effective input cost drops about seventy percent, taking the USD 40k bill to roughly USD 20k after caveats.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine paying a tutor to read your textbook out loud every time you have a question. Most of the textbook is the same; only the question changes. Prompt caching lets the tutor say 'I remember the textbook, just ask your question.' You still pay full price for the question itself and for the tutor's answer, but the textbook is now nearly free per session. Picture an app paying forty thousand dollars a month, where most of the input is the same long set of examples and rules. For that app, this move alone cuts the bill in half. The catch: the tutor only remembers the textbook if you bring it in the exact same words every time. You also have to ask the next question soon enough.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

A $40k monthly LLM bill where most input is shared across calls is the standard setup that prompt caching was built for. The savings are large, the mechanism is well-understood, and the operational gotchas are predictable.

Caching is the right move here. The work that remains is operational discipline rather than mechanism design.

How prefix memoization works at the provider

Every inference call builds an attention KV cache as the model processes the prompt. The KV cache stores keys and values for each token across each layer, and the prefill phase walks the prompt forward to build it. Once the prefill is done, decode generates one token at a time against the cached state.

Prompt caching reuses that prefill work across calls. Open-source servers show how: vLLM's automatic prefix caching hashes blocks of prompt tokens and stores their KV cache against the hash. A later request with the same hash reuses the stored state instead of recomputing it. Hosted APIs expose the same idea at the API layer. The cost savings come from skipping the prefill compute on the cached portion. The model still has to do prefill on the fresh suffix and full decode on the output.

A cache hit needs an exact match on the prefix. Even a single character change breaks the match. This is why byte-exact match is the binding constraint on hit rate. Providers expose either explicit cache markers (Anthropic's cache_control) or automatic caching above a length threshold (OpenAI). In both cases the idea is the same: reuse the work done on an identical prefix.

The savings math for the $40k workload
Byte-stability and the silent failure mode
Provider-specific knobs: markers, TTL, model pinning
Action items and the rollout playbook
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Anthropic prices prompt cache reads at 0.1x base input on most Claude models, so a stable system plus few-shot prefix costs about a tenth of its normal price on each hit.
  • OpenAI caches long prefixes automatically and reports hits as usage.prompt_tokens_details.cached_tokens (Chat Completions) or usage.input_tokens_details.cached_tokens (Responses API), which teams track as the hit-rate metric.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow would you measure cache hit rate after rollout?
A

Track usage.prompt_tokens_details.cached_tokens (OpenAI) or cache_read_input_tokens (Anthropic) per call type; expect a high ratio on stable workloads; alert on drops as invalidation regressions.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Counting output tokens in the projected savings; caching is input-side only and output is always billed at full rate.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Which tokens are cacheable in a system plus few-shot setup

  • Anthropic tenfold vs OpenAI model-dependent cached-token discount

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Estimate the per call cost of a typical RAG chatbot using GPT-4o-mini.
Flashcard·Easy