Articles

Cut LLM Costs with Prompt Caching: A Practical Guide

Prompt caching can slash LLM API costs and latency by reusing repeated context. Here's how it works, what to cache, and the silent mistakes that break it.

Chisato Chisato · · Updated · 4 min read
Abstract art of language-model tokens

Here’s a bill-shock moment many teams hit: you build an AI feature with a long system prompt, a few examples, and maybe a big reference document — and then realize you’re paying to re-process all of that text on every single request. The same 5,000 tokens of context, billed again and again. Prompt caching is the fix, and it can cut both your costs and your latency dramatically with very little code.

What prompt caching is

When you send a prompt, an LLM has to process every token before it can respond. Prompt caching lets the provider save the processed state of a prefix of your prompt and reuse it on later requests that start with the same content. Like any cache, it trades a little storage for a lot of repeated work — the repeated part is served from cache instead of being recomputed.

The economics are lopsided in your favor. Reading from cache typically costs around one-tenth of the normal input price, while writing to the cache costs a bit more than a normal request (commonly about 25% extra for a short-lived cache). So the first request pays a small premium to populate the cache, and every request after that rides nearly for free on the cached portion.

To see what caching does to your own bill, plug your traffic into our free LLM token cost calculator — it models cache hit rates and the batch discount alongside current per-model prices.

The one rule that governs everything

Prompt caching is a prefix match. The cache key is the exact sequence of tokens from the start of your prompt up to a cache point. That leads to a single, unbreakable rule:

Any change anywhere in the prefix invalidates the cache for everything after it.

Put differently: stable content first, volatile content last. The model processes your request in a fixed order — tool definitions, then the system prompt, then the conversation — so anything that changes between requests must come after the parts you want to reuse. Get the ordering right and caching mostly works for free; get it wrong and no amount of configuration will save you.

What’s worth caching

Cache the big, stable chunks that repeat across requests:

  • Long system prompts and instruction sets.
  • Tool/function definitions in agent setups.
  • Large reference documents or knowledge you stuff into context.
  • Few-shot examples shared across many queries.
  • Conversation history in multi-turn chats, so each turn reuses everything before it.

Put the variable part — the user’s actual question, a per-request ID, the current timestamp — at the very end, after the cached prefix.

The economics, concretely

OperationTypical cost vs. normal input
Cache write (first request)~1.25× (short TTL)
Cache read (later requests)~0.1×
Uncached input

Caches expire after a short window (often around five minutes), refreshed each time they’re used, with longer-lived options available at a higher write cost. The break-even is fast: if a cached prefix is reused even a couple of times within its lifetime, you come out ahead. For a busy endpoint or a long agent run, the savings are enormous.

The silent mistakes that break it

Caching fails quietly — no error, just a bill that never drops. Audit your prompt-building code for these:

  • A timestamp or UUID near the top. Current time: 2026-06-20 14:03:11 in the system prompt changes every request and invalidates everything after it.
  • Non-deterministic serialization. Dumping a dictionary or set without sorting keys can reorder bytes between requests. Serialize deterministically.
  • Per-user data in the prefix. Interpolating a user’s name or ID into the system prompt gives every user a unique prefix and kills cross-request sharing.
  • Changing tools or models mid-conversation. Tool definitions sit at the very front; adding or reordering one invalidates the whole cache. Switching models invalidates it too — caches are per-model.

Verify it’s actually working

Don’t assume — measure. Provider responses report cache activity in their usage data (look for fields like cache_read_input_tokens). If that number stays at zero across repeated requests with what should be an identical prefix, a silent invalidator is at work. Diff the exact bytes of two requests’ prefixes to find it.

The takeaway

Prompt caching is one of the highest-leverage optimizations in any LLM application: a small change to how you order your prompt can cut input costs by an order of magnitude on repeated context. It pairs especially well with reasoning models, which spend extra tokens thinking — caching the stable input offsets the cost of the deliberation. Freeze your prefix, push the variable bits to the end, and confirm the cache is being read. For the bigger picture on building cost-effective AI features, see our look at the state of AI coding assistants in 2026.

Chisato Chisato · · 4 min read

What Is Prompt Chaining? Multi-Step LLM Pipelines

Prompt chaining splits a task into a sequence of smaller LLM calls, each one feeding the next, instead of asking one giant prompt to do everything.

#AI #LLMs #Developer Tools
Chisato Chisato · · 4 min read

What Is Semantic Caching for LLM Applications?

Semantic caching reuses an LLM's past response for a new prompt that means the same thing, by comparing embeddings instead of exact text.

#AI #LLMs #Performance