Prefix Caching for Multi-Turn LLM Agents
Connor Blier
Founding GTM
Prefix Caching for Multi-Turn LLM Agents
For a multi-turn agent on serverless GPU, prefix caching recovers the repeated prefill over its own context: the system prompt, tool schemas and conversation history re-sent every turn. At a 90% hit rate that reclaims roughly 83% of prefill cost and collapses time-to-first-token, provided the cache survives between turns.
Multi-turn agents spend most of their compute re-reading their own context. A ReAct agent making ten tool calls might emit 500 output tokens while consuming 800,000 input tokens, because every call re-sends the full system prompt, tool schemas, and conversation history. Prefix caching recovers that wasted prefill, and at a realistic 90% hit rate it cuts effective prefill cost by roughly 83%. The catch on serverless is that the cache does not survive a cold start or a new replica, so your hit rate has to be engineered, not assumed.
If you are sizing agent infrastructure more broadly, our GPU inference for AI agent workloads guide covers model sizing and routing; this piece stays focused on the prefill/KV-cache layer.
Why prefill, not generation, is the bottleneck
Production agents are not compute-bound on generation. They are compute-bound on context. The Spheron context-engineering write-up puts the input:output ratio for a ten-call ReAct session at 100:1, and notes that "the model generation step takes milliseconds. The prefill pass over 80,000 input tokens takes seconds, and you pay for it on every call."
That prefill is expensive in absolute terms. Generating the KV cache for a 72K-token input on an A100 takes about 30 seconds. Every turn that re-prefills that context is paying the full tax again.
What prefix caching is and what it reuses
KV reuse
Prefix caching stores the KV cache of prior requests and lets a new request skip the compute for any prefix it shares. vLLM's Automatic Prefix Caching "caches the KV cache of existing queries, so that a new query can directly reuse the KV cache if it shares the same prefix." For agents this is a near-perfect fit: system prompts and tool schemas are fixed, so as the KVFlow paper observes, "these prompts remain constant across iterations" and caching "avoids redundant computation on static content."
vLLM vs SGLang implementations
The two dominant engines match prefixes differently. vLLM hashes 16-token blocks; SGLang's RadixAttention uses a radix tree, which reaches up to 6.4x higher throughput on prefix-heavy traffic. At 80% shared prefix and 50 concurrent requests, TTFT p50 drops from 310 ms on vLLM to 195 ms on SGLang, a 37% reduction. We compared both engines end to end in our vLLM, SGLang and TensorRT benchmark.
What it recovers: cost and TTFT
Cost math
Because prefill dominates, cache hits translate almost directly into cost cuts. At a 90% hit rate against a 92% prefill fraction, the saving is 0.90 x 0.92 = 82.8%. This is not theoretical: OpenAI, Anthropic and DeepSeek have all integrated prefix caching and report lowering inference costs by over 50%. For the full unit-economics picture, see our LLM inference cost at scale guide.
Latency math
The same reuse collapses time-to-first-token, since TTFT is dominated by prefill. The 310 ms to 195 ms drop above is the reuse effect at 80% overlap. For context on where TTFT sits in a full request, in our benchmarks vLLM hit the lowest TTFT of 123 ms on 1xH100 at 256 input tokens, batch size 1, measured as the total roundtrip to the Cerebrium platform.
Hit rate decides both
Everything above scales with one number. As the llm-d team puts it, "the KV-cache hit rate is the single most important metric for a production-stage AI agent. It directly affects both latency and cost." Character.AI runs KV cache reuse at 95% while serving over 20,000 queries per second, which is the target to aim for.
The serverless catch
Scale-to-zero destroys the cache
The KV cache lives in GPU memory. When a serverless replica scales to zero, that memory is gone. Worse, the first request after a cold start pays a load penalty: Spheron measures a 40-90 second penalty "the first time a pod has to load a large model from scratch," and the cache does not survive that restart. So your first post-idle turn gets zero cache benefit and the full prefill.
Multi-replica breaks single-instance caching
APC is a single-instance optimization. As llm-d notes, "the moment you scale to a distributed, multi-replica environment, these finely tuned optimizations can fall apart" because requests scatter across pods and a follow-up turn can land on a replica that never saw the prefix. Naive round-robin routing turns a 95% hit rate into a coin flip.
The cold-start floor
The good news is the floor can be low with the right engine packaging. On Cerebrium, the TensorRT-LLM Llama 3 8B engine takes roughly 10-15 seconds to load the model into GPU memory on a cold start, well under the 40-90 second range for naive large-model loads. We cover the mechanics of driving this down in serverless GPU cold starts for voice AI, and how platforms differ in Modal alternatives for serverless GPU inference.
Engineering hit rate on serverless
Three levers matter:
Keep replicas warm. Scale-to-zero is the enemy of cache hit rate. Holding a minimum warm replica preserves the KV cache across turns and eliminates the cold-start prefill on the next request.
Route to the instance holding the prefix. In multi-replica deployments, session-aware routing that pins a conversation to the replica that already cached its prefix is what keeps hit rate near the Character.AI 95% figure rather than collapsing it.
Accept a recompute tax where it is cheaper. When neither is possible, budget for the full prefill and keep the prefill itself fast.
Throughput headroom makes that tax survivable. SGLang reached 460 tokens per second at batch size 64 in our benchmarks, and the TensorRT-LLM tutorial achieves ~1700 output tokens per second (FP8) on a single A10. Once you are pushing tokens across a network, prefill savings can be swamped by round trips, so also tune the path itself, see network latency in the AI inference pipeline and the TensorRT-LLM on serverless GPUs walkthrough. Our global voice agent architecture shows the warm-replica pattern in a latency-critical setting.
Key takeaways
Agent traffic is mostly re-sent context; prefill, not generation, drives cost and TTFT.
At a 90% hit rate you recover ~83% of prefill cost, and TTFT drops sharply on shared prefixes.
Hit rate is the single metric that governs both, and on serverless it is not free: scale-to-zero and multi-replica scale-out both destroy the cache.
Engineer hit rate with warm replicas and session-aware routing, and keep cold starts and prefill fast so the recompute tax stays cheap.
Frequently asked questions
- Does the prefix cache survive a serverless cold start?
- No. The KV cache lives in GPU memory, so when a replica scales to zero the cache is destroyed and the next request pays a full prefill. Naive large-model cold starts run 40-90 seconds; on Cerebrium a TensorRT-LLM Llama 3 8B engine loads in roughly 10-15 seconds. Keeping a warm replica is what preserves the cache across turns.
- How much can prefix caching actually save on cost?
- For agent workloads where prefill is ~92% of compute, a 90% hit rate cuts effective prefill cost by about 83% (0.90 x 0.92 = 82.8%). In practice OpenAI, Anthropic and DeepSeek report over 50% inference cost reductions from their prefix caching implementations.
- vLLM or SGLang for prefix-heavy agent traffic?
- Both cache prefixes, but differently. vLLM hashes 16-token blocks; SGLang's RadixAttention uses a radix tree for finer matching, reaching up to 6.4x higher throughput on prefix-heavy traffic and 37% lower TTFT at 80% shared prefix (195 ms vs 310 ms). In our own benchmarks vLLM had the lowest TTFT at 123 ms, while SGLang led on throughput at 460 tokens/sec.
- What is the single most important metric to track?
- KV cache hit rate. It directly governs both latency and cost. Character.AI sustains a 95% hit rate at over 20,000 queries per second; on serverless you reach that number by keeping replicas warm and routing follow-up turns to the instance already holding the prefix.
Get started with Cerebrium
Deploy AI models on serverless GPUs in minutes, with no infrastructure to manage. Start for free and pay only for the compute you use.
Sources
- docs.vllm.ai
“Automatic Prefix Caching (APC in short) caches the KV cache of existing queries, so that a new query can directly reuse the KV cache if it shares the same prefix with one of the existing queries, allowing the new query to skip the computation of the shared part.”
- spheron.network
“A ReAct agent making 10 tool calls in a session might produce 500 output tokens total and consume 800,000 input tokens, because each call carries the full system prompt, tool schemas, and conversation history. The model generation step takes milliseconds. The prefill pass over 80,000 input tokens takes seconds, and you pay for it on every call.”
- spheron.network
“Production agents are not compute-bound on generation. They are compute-bound on context. A ReAct agent making 10 tool calls in a session might produce 500 output tokens total and consume 800,000 input tokens, because each call carries the full system prompt, tool schemas, and conversation history.”
- spheron.network
“At 90% hit rate, 92% prefill fraction: cost_saving = 0.90 * 0.92 = 82.8%”
- llm-d.ai
“The _KV-cache hit rate is the single most important metric for a production-stage AI agent. It directly affects both latency and cost_.”
- llm-d.ai
“In a single-instance environment, engines like vLLM leverage Automatic Prefix Caching to cut redundant work, reusing prior computations to drive faster, more efficient performance. However, the moment you scale to a distributed, multi-replica environment, these finely tuned optimizations can fall apart.”
- arxiv.org
“Since these prompts remain constant across iterations, prefix caching avoids redundant computation on static content and significantly reduces per-agent inference latency.”
- spheron.network
“vLLM hashes 16-token blocks; SGLang's RadixAttention uses a radix tree, hitting up to 6.4x higher throughput on prefix-heavy traffic.”
- spheron.network
“at 80% shared prefix and 50 concurrent requests, TTFT p50 drops from 310 ms on vLLM to 195 ms on SGLang, a 37% reduction that holds across the concurrency levels tested below.”
- arxiv.org
“Leading LLM service providers, including OpenAI, Anthropic, and DeepSeek, have integrated prefix caching mechanisms into their inference systems, lowering inference costs by over 50%.”
- arxiv.org
“For example, generating the KV cache for a 72K-token input (e.g., a 200-page book such as The Great Gatsby) using Llama2-70B on an NVIDIA A100 GPU takes approximately 30 seconds, significantly impacting user experience.”
- spheron.network
“Character.AI runs KV cache reuse at 95% while serving over 20,000 queries per second.”
- spheron.network
“Serverless GPU promises zero infrastructure management and scale-to-zero billing. It delivers both, at the cost of a 40-90 second penalty the first time a pod has to load a large model from scratch.”
- cerebrium.ai
“This code will run on every cold start and takes roughly ~10-15s to load the model into GPU memory.”
- cerebrium.ai
“The following benchmark was done with 256 input tokens on 1xH100 of batch size 1. This was the total roundtrip time of a request made to the Cerebrium platform.”
- cerebrium.ai
“From our tests, it seems that vLLM is the best framework for use cases looking for the lowest TTFT of 123ms which is extremely quick if you take into consideration network latency.”
- cerebrium.ai
“As for throughput use cases, it seems SGLang was a clear winner achieving a throughput of 460 tokens per second on a batch size of 64.”
- cerebrium.ai
“In this tutorial we will achieve ~1700 output tokens per second (FP8)on a single Nvidia A10 instance however you can go up to ~4500 output tokens per second on a single Nvidia A100 40GB instance or even ~19,000 tokens on a H100.”