KV Cache
What is KV Cache?
A KV cache is memory in which a language model stores the key and value data computed for tokens it has already processed, so it need not repeat that work for each new token.
Updated November 2026 · 5 min read
The KV cache is a core part of how language models run efficiently. When a model generates text, each new token depends on all the tokens before it. The model's attention mechanism represents every previous token as a pair of vectors, called keys and values. Rather than recomputing these for the whole sequence every time a new token is produced, the model stores them in the KV cache and reuses them. This makes generation much faster, but it uses a large amount of GPU memory, and that memory grows with every token in the context and every request being served at once.
The KV cache sits at the heart of inference economics. Its size limits how many requests a GPU can serve together and how long the context can be, which in turn determines throughput and cost per token. It is also the mechanism behind prompt caching, where providers reuse stored keys and values across requests to offer discounts. For IT financial management, the KV cache explains why long contexts cost more, why GPU memory matters as much as GPU speed and why some of the most effective inference optimizations focus on managing this memory.
Definition of KV Cache
A KV cache, short for key-value cache, is a store of the attention keys and values a transformer model has computed for previous tokens in a sequence. It is kept in GPU memory during inference and extended by one entry for each new token.
The cache exists only to avoid repeated computation. Without it, generating each token would require reprocessing the entire sequence, making output far slower and more expensive.
Memory Use
The KV cache grows with the length of the context window in use, the number of layers and attention heads in the model, and the number of requests being processed at the same time.
For long contexts, the cache can require more GPU memory than the model's own weights. This limits how many requests fit on a GPU at once and how long each can be.
Memory, rather than raw computation, is often the factor that limits how much work a GPU can do for language model inference, which is why GPUs with more memory command higher prices.
Reuse Across Requests
When many requests share the same opening content, such as a common system prompt, the keys and values for that content are identical. Storing and reusing them avoids recomputing them for every request.
This is the basis of prompt caching, which providers offer as a discounted price for repeated input.
Self-hosted serving software can also reuse cached prefixes across requests, reducing compute and improving response times.
Importance of KV Cache in IT Financial Management
The KV cache links technical design to cost. Because it consumes GPU memory in proportion to context length and concurrent requests, it determines how many users a given amount of hardware can serve.
Long-context applications and agents with growing histories put heavy pressure on the KV cache, reducing throughput and raising cost per request.
Understanding this helps explain pricing that seems puzzling at first, such as higher per-token rates for very long requests or large discounts for cached input. Both reflect what the KV cache costs the provider to hold.
Throughput and Cost per Token
For self-hosted models, more requests served at once means more tokens per second per GPU and a lower cost per token. KV cache memory is often what limits that concurrency.
Techniques that use KV cache memory more efficiently, such as paged memory management, compression of cached values and sharing of common prefixes, allow more requests per GPU.
These improvements directly reduce cost per token, which makes KV cache management a central part of inference optimization.
Context Length Decisions
Every token kept in context occupies KV cache memory for the duration of a request. Applications that send long documents or histories use more memory per request and serve fewer users per GPU.
Reducing context, by retrieving only relevant content or summarizing history, therefore saves not only input tokens but also GPU memory and capacity. For self-hosted services, this can mean needing fewer GPUs for the same number of users.
The same logic explains why providers price long contexts higher: they consume more of the provider's scarcest resource.
How to Manage the KV Cache
For organizations using model APIs, the KV cache is managed by the provider, and the main lever is prompt design that benefits from caching and keeps context lean.
For organizations running their own models, KV cache management is a key part of serving configuration and capacity planning.
For API Users
Structure prompts so that stable content comes first and can be served from the provider's cache at a discount.
Keep context as short as quality allows, since long contexts cost more and may trigger higher pricing tiers.
Monitor cached input tokens and context length per request as indicators of how efficiently applications use model memory. Rising context length is often the earliest sign of growing costs.
For Self-Hosted Models
Use serving software that manages KV cache memory efficiently, supports prefix sharing and allows many requests to be batched together.
Consider compressing or quantizing the KV cache, which reduces memory use with a small effect on quality, and choose GPUs with enough memory for the expected context lengths and concurrency.
Measure tokens per second per GPU at realistic context lengths, since throughput at short contexts can overstate real capacity.
Examples of KV Cache in IT Financial Management
The examples below show the KV cache affecting cost and capacity.
Both use illustrative figures. The first improves throughput for a self-hosted model, and the second shows the effect of context length on capacity.
In each, managing KV cache memory changed how much work the same hardware could do.
Improving Serving Efficiency
A company serves an open-weight model on four GPUs, handling about 24 requests at a time before memory runs out. Throughput is about 1,800 tokens per second.
It switches to serving software with paged KV cache management and prefix sharing for its common system prompt, and compresses cached values to 8-bit precision.
The same GPUs now handle about 70 concurrent requests at about 4,600 tokens per second, reducing cost per token by more than half.
Context Length and Capacity
Another company plans a document analysis service that sends 100,000-token contexts. Testing shows each GPU server can handle only four such requests at once because of KV cache memory.
Switching to retrieval that sends about 15,000 tokens of relevant passages allows about 25 concurrent requests per server.
The service needs one server instead of six for its expected load, saving about $40,000 a month in GPU costs, and answers improve because the model sees focused content.
Conclusion
A KV cache stores the keys and values a language model computes for previous tokens so it does not recompute them for each new token. It makes generation fast but consumes GPU memory in proportion to context length and the number of requests served at once.
In IT financial management, the KV cache explains why long contexts cost more, why GPU memory limits throughput and how prompt caching discounts work. Structuring prompts for caching, keeping context lean, using efficient serving software and planning GPU memory for real context lengths help organizations serve more AI work for the same cost.
Related terms
Context Window
A context window is the maximum number of tokens a language model can consider at once, covering its instructions, the conversation so far, any supplied documents and the response it generates.
Prompt Caching
Prompt caching is a technique in which an AI provider stores the processed form of repeated prompt content, such as standard instructions, so later requests can reuse it at lower cost and latency.
Inference Optimization
Inference optimization is the set of techniques used to make running AI models faster and cheaper, such as batching, caching, quantization, efficient serving software and smaller models, without unacceptable loss of quality.
Tokens per Second
Tokens per second is the rate at which an AI model generates or processes tokens, used to measure the speed of a model for one user and the throughput of AI infrastructure across many.