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

Gemini Implicit Caching

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.

A default project has a possible route from RAM to encrypted SSD. An approved ZDR project has a RAM shelf only.
The SSD deadline runs from prefix creation. A project with an approved zero data retention exception stays on the memory-only path.

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.

Two requests start with the same service catalog. One ends with a region question and the other with an uptime question.
Keep the catalog in place and swap the question at the end. Read each response's usage fields to find out whether Gemini reused the catalog.

On each returned interaction, read the total input and the cached portion. This is the calculation in Google's cache measurement example.

Python
usage = interaction.usage
total_in = usage.total_input_tokens or 0
cached = usage.total_cached_tokens or 0
uncached = total_in - cached

A 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

Who else could use itWhat to keep at the frontWhat the team gains
A procurement analyst reviewing a supplier agreementThe same agreement and annexes in a fixed order, followed by a question about renewal or deliveryThe analyst can ask a fresh question about another clause while earlier document processing remains eligible for reuse.
A release engineer investigating a failed buildA fixed build log, followed by each investigator's questionColleagues can explore different failure hypotheses against the same evidence and measure the input charged for each investigation.
A course editor checking lessons against a style guideThe long editorial guide, followed by the lesson under reviewSeparate reviews can share the guide while each lesson receives its own feedback.

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
Related Articles
Claude Terraform Provider

Claude Terraform Provider

Create one Claude workspace per client, review agent changes before applying them, and see which resources AWS, Google Cloud and Bedrock support.BuildDec 5
Codex CLI Cloud

Codex CLI Cloud

Start and reopen Codex cloud chats from the terminal, choose a project environment, and review local and cloud tasks in the Agent Command Center.BuildDec 5
GPT-Live API: Build a Voice App With WebRTC, a Sideband and Delegation

GPT-Live API: Build a Voice App With WebRTC, a Sideband and Delegation

Build a voice app on the GPT-Live API: open a WebRTC session, attach a sideband, delegate to a backend, keep state, test it and price each call.BuildDec 5
AI SDK 7.1 for TypeScript agents: what to adopt first

AI SDK 7.1 for TypeScript agents: what to adopt first

Which AI SDK 7.1 features belong in your agent? Start with tool ordering and steering, check your 7.0 patch, then choose batch, audio or durable execution.BuildDec 5
Codex Models by Surface and Task

Codex Models by Surface and Task

Choose a Codex model for your task and plan, see where GPT-5.6 threads go, and set a default or a one-run CLI override.BuildDec 5
Claude Settings JSON

Claude Settings JSON

Find Claude Code’s settings.json, see which file wins, and copy five examples for permissions, hooks, models, the status line and compaction.BuildDec 5
How to Run Qwen 4 Locally

How to Run Qwen 4 Locally

Run Qwen4-35B-A3B with Ollama, LM Studio, llama.cpp or vLLM. Match GGUF sizes to your GPU or Mac and leave room for context.BuildDec 5
OpenRouter API Key: Create a Key and Send Your First Request

OpenRouter API Key: Create a Key and Send Your First Request

Create an OpenRouter API key, set a spending limit, and send your first request with curl or the OpenAI Python SDK. See the documented reply and error fixes.BuildDec 5
Newsletter

One letter, every Sunday.Working systems, not hot takes.

Weekly. No spam. Unsubscribe anytime.