Why Long AI Chats Get Expensive
Why Long AI Chats Get Expensive: Prompt Caching and the Way History Is Trimmed
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
| Work | What it reuses | The condition |
|---|---|---|
| Prompt Cache (MLSys 2024) | "precomputing and storing the attention states" of frequently occurring text segments | They "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 tree | Reuse 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 requests | A 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
- Use your real prompt code. Build each turn's prompt with the same functions your app uses, in the same order.
- Replay scripted conversations, long enough to pass the limit, with fixed random seeds. No user data is needed.
- 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.
- 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.
- Check your filler text. Scripted words can trigger features in your app you didn't mean to test.
- Report history kept next to reuse, for every variant you try.
- 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
- 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
- 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
- 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
- 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