Prompt Caching: Cut LLM Costs and Latency for Repeated Context

How prompt caching works, which parts of a prompt can be cached, structuring prompts for cache hits, pricing effects and measuring hit rates.

Published December 1, 2026

Many LLM requests repeat the same large prefix: a long system prompt, tool definitions, a policy document, or a codebase summary, followed by a short new question. Prompt caching lets the provider reuse the processed prefix instead of recomputing it, which can cut input cost substantially and reduce time to first token. For chatty agents and document Q&A, it is one of the biggest optimisations available.

The concept

Caching works on prefixes. The provider stores the model's internal state for the beginning of a prompt; a later request that starts with exactly the same tokens can reuse it. Any change early in the prompt, even a timestamp or a reordered tool list, breaks the match for everything after it. Depending on the provider, caching is automatic above a minimum length or enabled with explicit cache markers, and cached entries expire after a short idle period unless refreshed.

Pricing typically has three parts: normal input tokens, cache writes (sometimes slightly more expensive), and cache reads (much cheaper than normal input). The savings therefore depend on reuse: a prefix read many times within its lifetime is a big win; a prefix written and never read again can cost more.

How caching works

first callwithin TTLhitRequest 1prefix + Q1Cache writeprefix storedRequest 2..Nsame prefix + QnCache readcheap + faster
Identical prefixes are processed once and reused.

Structuring for cache hits

Prompt sectionStabilityPlace it
System instructionsStableFirst
Tool definitionsStable (keep order fixed)Early
Reference documentsStable per sessionBefore conversation
Conversation historyGrows (append-only)After stable parts
Timestamps, user-specific volatile dataChanges every callLast

Savings depend on hit rate

No caching100% input cost50% hit rate≈55%90% hit rate≈19%
Illustrative relative input cost when cached reads are billed at ~10% of normal input.

Practical examples

Cache-friendly message layout

Stable content first, volatile content last.

messages = [
  {"role": "system", "content": SYSTEM_PROMPT},          # stable
  {"role": "user", "content": POLICY_DOCUMENT},          # stable for the session
  *conversation_history,                                 # append-only
  {"role": "user", "content": f"(Today is {date}) {question}"},  # volatile last
]

Explicit cache breakpoint (provider-specific syntax)

Some APIs let you mark where the cacheable prefix ends.

{"type": "text", "text": POLICY_DOCUMENT, "cache_control": {"type": "ephemeral"}}

Measure hit rate from usage fields

Responses report cached vs uncached input tokens.

u = response.usage
hit_rate = u.cached_input_tokens / max(1, u.input_tokens)   # field names vary by provider
metrics.histogram("llm.cache_hit_rate", hit_rate)

Common mistakes

  • Putting the current timestamp or request ID at the top of the system prompt.
  • Building tool lists in random order (e.g. from an unordered set).
  • Assuming caching is on without checking usage fields.
  • Caching prefixes that are rarely reused before they expire.

Key takeaways

  • Prompt caching reuses identical prompt prefixes.
  • Put stable content first and volatile content last.
  • Savings depend on reuse within the cache lifetime.
  • Monitor cached-token usage to confirm hits.

FAQ

Does caching change model outputs?

No. It only avoids recomputing the prefix; outputs are the same as without caching.

Is cached data shared between customers?

Providers isolate caches per organisation or account; check your provider's documentation for specifics.

How long do cache entries last?

Typically minutes of inactivity, sometimes extendable; each hit usually refreshes the lifetime.

More AI articles