KV Cache
A KV cache (key-value cache) is a technique used when a large language model (LLM) generates text. The model keeps the attention "key" and "value" tensors it has already computed for earlier tokens in GPU memory and reuses them for each new token, instead of recomputing the whole context every time.[2] This speeds up generation. The trade-off is memory: the cache grows with the length of each sequence, so it becomes a key factor in LLM serving cost and in how much context a system can handle at once.[1][2] Prompt caching offered by API providers applies the same idea across requests: it saves the key-value state for a repeated prompt prefix and reuses it.[9]