Gemini Implicit Caching
Put shared input first, read cached tokens on each Gemini 4 response, and see how durable storage differs for projects with approved zero data retention.
Published

A support bot can send the full returns policy with every ticket and pay the cached input rate when Gemini recognizes the repeated opening. Since December 4, Gemini 4 can sometimes reuse that work even after the policy leaves memory. Keep the policy first, put the customer's question last, and check the response to see how much input actually qualified.
What survives when a prefix leaves memory?
A prefix is the part of a request that matches an earlier request from the very beginning. Think of a service manual with a question clipped to the back. A technician who has already read the manual can turn straight to the new question. Gemini can similarly reuse work on the opening tokens, the pieces of text or other input the model processes. It still generates an answer for this request.
The December 4 changelog changes where that work can go for Gemini 4 models. When Gemini 4 evicts a prefix from working memory (RAM), it may keep it in encrypted durable storage on a solid-state drive (SSD), at no extra storage fee. The limit is up to 12 hours from creation. Eviction from RAM does not start a fresh clock. Capacity and request routing can still produce a miss, even if the next caller sends exactly the same policy.

The distinction matters if you run customer workloads. The durable cache is scoped to your project. A project with an approved zero data retention (ZDR) exception is opted out of SSD storage and can still get a hit from RAM. Setting store=False on an Interactions API call turns off server-side conversation storage. The project's implicit caching policy still applies. Google's zero data retention terms
Implicit or explicit caching?
On Gemini 4, use implicit caching. You send ordinary requests, and Gemini automatically looks for a reusable opening. There is no cache to name, refresh or delete in your application. For an existing support bot, the code worth reviewing is the function that assembles each ticket's prompt.
Explicit caching gives the application a different job. On supported Gemini 3 and Gemini 2.5 models using generateContent, you create a cache object, choose its lifetime and reference it in later calls. Gemini 4 and the Interactions API do not support those explicit objects. If you are migrating, replace the cache reference with the shared content or file reference and measure reuse on the new calls. Gemini's context caching guide
On the standard paid tier, Gemini 4 Neon costs $0.15 per million cached input tokens, versus $3.00 per million ordinary input tokens. Gemini API pricing
Put the shared work first
Suppose a support template opens with “Ticket received at…” and then includes the entire handbook. The timestamp may differ before Gemini reaches a single policy clause. Move the timestamp into the final user message alongside the ticket ID and question. Keep the common policy in the system instruction. A genuine change to the returns window belongs in that instruction immediately, even when it breaks a match.
The API assembles model settings and tools ahead of the system instruction, then adds conversation history and user input. An identical handbook alone is insufficient if your application changes the thinking level or shuffles ordinary function declarations ahead of it. Keep those stable when the task allows. If several questions refer to uploaded documents, put the file references in the same order before each question.
Gemini 4 requires at least 4,096 input tokens for implicit caching. It also recomputes at least the trailing 2,050 tokens at standard input rates. A short “continue” after a long turn can therefore incur ordinary input charges for some earlier history. Cached tokens still occupy the context window and count toward the tokens-per-minute limit.
Read a hit in the response
Google's example makes two calls to Gemini 4 Neon using the same catalog of 400 service entries. The first asks which region hosts Service 3. The second asks for Service 7's uptime commitment. The catalog matches up to the point where the question changes.

On each returned interaction, read the total input and the cached portion. This is the calculation in Google's cache measurement example.
usage = interaction.usage
total_in = usage.total_input_tokens or 0
cached = usage.total_cached_tokens or 0
uncached = total_in - cachedA positive cached count tells you Gemini reused that many input tokens on this call. Subtracting it from total input gives the part billed at the ordinary input rate. A zero on the second call means you observed no reuse. Check input length and the first place the requests differ before changing your template. The example supplies the questions and the measurement code, so you can run it on your project and record your own counts.
Where I would try it first
A support bot with one long policy is the first place to look. A returns team can keep the approved handbook fixed across independent tickets and append each customer's facts at the end. Two customers can ask entirely different questions and still share the policy prefix. The team can keep exceptions and escalation rules in full, then use cached input per ticket to decide whether shortening the handbook is worth the editorial work.
An agent loop comes next. Consider an operations agent that looks up a shipment and then checks its delivery exceptions. In a stateless loop, append the model's returned steps verbatim, including their signatures, before adding the next result. Rebuilding history from the text shown in chat can change the opening on every step. If you use previous_interaction_id for server-managed history, resend the same tools, system instruction and generation configuration on follow-ups that need them. Compare the cached input across steps as the history grows. How the Gemini Interactions API handles an agent's turns
Two tools worth building
Start with a prompt change check for the team that owns the support bot. Take two versions of its request builder, feed them the same sample tickets, and show the first differing field beside the observed cached and total input counts. The smallest useful report might say that a new ticket ID moved ahead of the policy. That gives the developer a specific edit to review. A miss alone cannot establish the cause, so keep request differences and observed usage visible together.
For an agent platform team, build a per-turn cost view. Start with a single workflow. Show the model, prompt version, total input and cached input for each step, using counts without retaining the conversation text. The team could see where a tool change coincides with a drop in reuse. The catch is that counters alone cannot reveal which tool declaration changed. The prompt change check is the stronger first build because it can locate an avoidable difference before release.
There is already a paid market for adjacent work. Langfuse's pricing page lists its Core plan at $29 a month and includes prompt versioning and tracing. That is a price for a broader product. For either idea, I would test whether an existing customer wants this particular view inside the tool they already use before building a separate dashboard.
Why is Gemini context caching not working on my second call?
Check that the request clears the 4,096-token floor. Compare settings, tool definitions and file order before inspecting the question. If the prefix matches, the entry may already have been evicted. A second request is an opportunity to reuse input, never a reservation.
Can I use a GitHub integration that creates explicit Gemini caches?
Check which model and endpoint the integration calls. Code that creates a named cache for a supported model on generateContent needs a different request for Gemini 4. Send the shared material at the start of the prompt and inspect cached input on the response.
Does context caching work with the Batch API?
Google lists implicit caching for Gemini 4 across service tiers, including Batch. The Neon price quoted above is for Standard. Use the Batch column when budgeting a batch job, and allow for cache misses.
If the choice of provider depends on where customer data can persist, compare zero data retention platforms for enterprise agents. For help instrumenting a live workflow, see AI production systems.
- Published
- Category
- Build







