Menu

Why Long AI Chats Get Expensive

Why Long AI Chats Get Expensive: Prompt Caching and the Way History Is Trimmed

Notes · Event-drivenNovember 25, 20264 min readSenova Systems Research

Serving systems can reuse the work of processing a prompt, but only for an identical start. Chat apps that drop the oldest message every turn change that start every turn, so long conversations are processed again from scratch. Here is how prefix caching works, the habits that defeat it, the trade-off of trimming in larger steps, and a free way to measure your own prompts.

The question

A chat with an AI assistant often gets slower and more expensive the longer it runs, even when each new message is short. Part of the reason is unavoidable: the model rereads the conversation every turn. Part of it is avoidable, and it comes down to one detail of how the conversation is cut to fit.

This note explains prompt caching, the common habit that quietly defeats it, and how to measure your own prompts. We report no results of our own here.

How to read this: each section gives the simple idea first, then The real detail. We opened every paper ourselves.

Serving systems can reuse work, but only for an identical start

The simple idea

Before a model writes a reply, it processes the whole prompt: instructions, history and the new message. If the start of this turn's prompt is exactly the same as last turn's, a serving system can keep that work and skip it. If anything near the start changes, everything after the change has to be processed again.

The real detail

WorkWhat it reusesThe condition
Prompt Cache (MLSys 2024)"precomputing and storing the attention states" of frequently occurring text segmentsThey "can only be reused if the segment appears at the same position". Reported time-to-first-word gains: "8× for GPU-based inference to 60× for CPU-based inference"
SGLang (RadixAttention)The model's working state for earlier calls, kept in a treeReuse across calls "that share a common prefix"; cache hit rates of 50 to 99% on its workloads, up to 6.4 times more throughput
vLLM (PagedAttention, SOSP 2023)Blocks of working state shared within and across requestsA prompt "with the shared prefix can simply map its logical blocks to the cached physical blocks"; 2 to 4 times more throughput at the same latency

The rule is the same in all three: reuse works for an identical prefix and stops at the first difference.

The habit that breaks it: trimming one message at a time

The simple idea

Every model has a limit on how much text it can take. When a conversation outgrows it, the usual fix is to drop the oldest message, then next turn drop the next oldest, and so on. Each of those turns, the start of the history is different from the turn before. Reuse then stops right after the fixed instructions, and the whole remaining history is processed again, every single turn, for the rest of the conversation.

The real detail

Not every design does this. MemGPT (UC Berkeley, 2023) evicts in large steps: at about 70% of the window it warns the model, and at 100% it removes a large block (its example is "50% of the context window") and replaces it with "a recursive summary of messages that have been evicted". MemGPT doesn't discuss caching. But a design that trims in large steps leaves the start of the history unchanged between trims, which is exactly what a prefix cache needs. That link is our reading, not a claim from the paper.

Other common prefix-breakers:

  • A clock in the instructions. A line like "the time is 14:07" at the top changes every minute.
  • Per-turn notes added to the instructions. Retrieved passages or mode hints that appear only on some turns.
  • A running summary placed early, rewritten every turn.

Each of these is cheaper to put next to the newest message, at the end, where change does no harm.

The trade-off to watch

The simple idea

Trimming in large steps keeps the prefix stable, but right after a trim the model sees less of the conversation than it would with one-at-a-time trimming. How large the step is decides the balance between saving and forgetting.

The real detail

The way to choose is to measure both sides for several step sizes: the share of each prompt that matches the previous turn's, and how much history the model keeps (on average and on the worst turn). A small step loses little history and saves less; a large step saves more and forgets more. Then check answer quality on real conversations before shipping, since a shorter worst case can matter more than a good average.

How to measure your own prompts, for free

  1. Use your real prompt code. Build each turn's prompt with the same functions your app uses, in the same order.
  2. Replay scripted conversations, long enough to pass the limit, with fixed random seeds. No user data is needed.
  3. For each turn, measure the longest shared prefix with the previous turn's prompt, as a share of the prompt. The newest message can never be reused, so compare with that ceiling.
  4. Run a sanity case first: a short chat with no trimming and nothing that changes should reuse almost exactly the ceiling. If it doesn't, the harness is wrong.
  5. Check your filler text. Scripted words can trigger features in your app you didn't mean to test.
  6. Report history kept next to reuse, for every variant you try.
  7. Then measure the real thing. Simulated reuse is an upper bound; caches also expire. If your provider or server reports how many input tokens came from cache, log that per call and compare.

The cheapest computation is the one you don't repeat. In a long chat, the order of the prompt decides how much gets repeated.

Sources

  1. Gim et al. 2024, Prompt Cache: Modular Attention Reuse for Low-Latency Inference (MLSys 2024)
    What we used

    Reuse only at the same position; 8x GPU, 60x CPU time to first token; opened 2026-11-25

  2. Zheng et al. 2023, SGLang: Efficient Execution of Structured Language Model Programs
    What we used

    Reuse across calls sharing a common prefix; 50-99% hit rates; up to 6.4x throughput; opened 2026-11-25

  3. Kwon et al. 2023, Efficient Memory Management for Large Language Model Serving with PagedAttention (SOSP 2023)
    What we used

    Shared-prefix blocks; 2-4x throughput; opened 2026-11-25

  4. Packer et al. 2023, MemGPT: Towards LLMs as Operating Systems
    What we used

    Eviction in large steps with a recursive summary; opened 2026-11-25

More in beyond the model

Computing Beyond the GPUNew kinds of computer promise to make AI far cheaper. We read the papers and separated measured results from claims: what each has run, at what size, and what it cost in energy. Most energy goes into moving weights, software has cut cost per answer faster than hardware, and the new chips need models built for them.3 minGetting Better Without RetrainingAI systems can improve after release by keeping skills, lessons and better instructions, without retraining the model. The same papers show the risks: lessons that crowd out what worked, and gains on average hiding losses. Here is the evidence and a protocol for measuring learning in use, including backward transfer and a frozen regression set.3 minSpend Compute Where It PaysMost AI requests are easy and a few are hard, yet many systems spend the same on both. Routers and cascades cut cost by half or more, models can learn to think less on easy questions, and voting can stop once answers agree. Here is what was measured, what goes wrong, and how to measure it.3 minMaking AI Work CheckableAsking a model to check itself often makes answers worse; a separate, sound checker helps. We read the research on turning work into something that can be run or looked up: code for maths, validators for plans, tests for code, sources for claims, and models as judges with their biases. It ends with a seven-step ladder of checkability.3 minThinking Longer vs Building BiggerA smaller model that tries several answers and checks them can beat a model many times its size, but only on the right problems. Every headline win, from AlphaGeometry to code that passes its tests, had a reliable checker. Here is when extra thinking pays, where it fails, and why the checker comes first.3 min