Context Caching

Context caching, also called prompt caching, is a service feature that reuses the processed form of input that repeats across language model requests. Many applications send the same long beginning with every call: system instructions, examples, a policy manual, or a document that several questions refer to. Processing that material costs time and money each time. With caching, the service keeps the result of processing a shared prefix and applies it to later requests that begin the same way, typically charging less for the cached tokens and, in some cases, returning the first output sooner.

Google’s Gemini API documentation describes the motivation as passing “the same input tokens over and over to a model”, and offers implicit caching, applied automatically: “We automatically pass on cost savings if your request hits caches.” Eligibility and minimum lengths vary by model. In the September 2026 Gemini documentation, implicit caching is available through the Interactions API, while explicit cache resources are documented for generateContent. Check the selected API rather than assuming both modes are available everywhere.

Order the prompt for reuse

Implicit prefix caching depends on matching tokenized content and service-specific model, configuration, and scope rules. Explicit caching instead creates a resource that later calls reference, subject to its lifetime and access rules. The same documentation advises putting large and common content at the beginning of the prompt and sending requests with a similar prefix within a short time. In practice this means stable instructions and reference material first, then per-request content such as the user’s question or the document to process. A changing timestamp or request identifier before the shared material can prevent reuse of that material. Moving it later improves eligibility but does not guarantee a hit.

An illustrative calculation shows the stakes. An extraction service sends 3,000 tokens of instructions and examples plus about 1,500 tokens of document per request. Without caching, two-thirds of its input tokens are the same instructions sent again. If cached tokens were billed at a quarter of the normal input price, the input-token charge on a fully cached hit would fall from 4,500 to 2,250 normal-price token equivalents, a 50% reduction before other charges. The actual discount, minimum size, and cache lifetime differ by service and must be checked; the response’s usage fields show how many tokens were served from cache, which measures actual token reuse. Also measure hit rate, storage or creation charges, TTL expiry, retries, and end-to-end latency. A 3,000-token prefix may be below a particular model’s minimum; the example assumes eligibility and a full hit.

What it does not change

Eligible cache hits can reduce input-processing work and token charges; total latency and total savings depend on the workload and service pricing. It does not directly change the number of output tokens, which depends on the answer the model generates rather than on whether the input was cached, and it does not change what the model does with the content. It also differs from caching results: a result cache returns a stored answer without calling the model, with all the questions of freshness and permission that raises, while context caching still runs the model on every request. It sits within the context window, so cached content still counts toward the model’s limit. The mechanism inside the model that makes this reuse possible, the key-value cache, is explained in LLM Inference Optimization.

References:


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.