We earn a reward if you sign up to SayGM through our links. Your price is the same.
LessPerToken

Gemini 4 context caching not working? How to fix it on Neon, Argon and Hydrogen

Gemini 4 changed how caching works. On Gemini 3.8 Flash and older you could upload a document once with caches.create, and every later call paid the cached rate. Gemini 4 Argon and newer (Neon, Carbon, Hydrogen) don't support that at all: they only have implicit caching, where Google decides what gets cached. If your bill went up after switching, or cachedContentTokenCount stays at 0, here's how to check, the five usual causes, and what to do about each.

Using Claude instead? It has the opposite problem: nothing is cached unless you ask. See Claude prompt caching not working?

1. Check whether anything is cached

Send the same long prompt twice, a few seconds apart, and read the usage block of the second response.

from google import genai

client = genai.Client()
corpus = open("corpus.txt").read()   # the same bytes on every call

for question in ["Summarise section 2.", "List the main risks."]:
    r = client.models.generate_content(
        model="gemini-4-neon",
        contents=[corpus, question],   # shared part first, changing part last
    )
    u = r.usage_metadata
    print(u.prompt_token_count, u.cached_content_token_count)
APICached tokens
generateContent, Python SDKusage_metadata.cached_content_token_count (None means 0)
generateContent, REST / JavaScriptusageMetadata.cachedContentTokenCount
Interactions APIusage.total_cached_tokens

If the second call shows a cached count close to the size of the shared part, caching works. If it's 0 or None, read on.

2. The five usual causes

You're still calling the explicit cache API

Code written for Gemini 3 creates a cache with client.caches.create(...) and passes cached_content=cache.name. On Gemini 4 that fails with 400 INVALID_ARGUMENT: Explicit caching is not supported for models/gemini-4-…. Google's caching docs say explicit caching isn't supported for Gemini 4 Argon and onward, and a Google reply on the developer forum (17 November) says the same for Hydrogen, Argon and Carbon. There's no setting that turns it back on: drop the cache calls and let implicit caching do the work.

The prompt is below the minimum

Implicit caching only starts at 4,096 tokens on Gemini 4. A 2,000-token system prompt is never cached, however often you send it, and there's no error to tell you.

Something changes before the shared part

Implicit caching matches the start of the request exactly. Anything that differs early makes every request look new:

  • a timestamp, request ID or user name at the top of the system instruction
  • documents sent in a different order each time
  • a per-batch instruction placed before the corpus instead of after it

Put everything that's the same on every call first, and the question, user and date last.

Requests are too far apart, or the turns are too small

Google's only guidance on timing is to send requests with the same prefix within a short time; implicit caches have no published lifetime. Chats and agent loops have a second rule: Gemini 4 caches the full previous request only if the new request adds at least 2,050 tokens (model output, thinking and function results count). For smaller additions, the last 2,050 tokens of the previous request are processed again at the normal input price. Most agent steps pass that; short chat replies often don't.

You're reading the wrong field

usage.total_cached_tokens belongs to the Interactions API. If you call generateContent, read cachedContentTokenCount, or you'll see 0 even when the cache works.

3. What to do instead

Make implicit caching hit

  • Put the large, identical content (documents, tool definitions, instructions) first, and keep it byte-identical between calls.
  • Make sure that shared part is well over 4,096 tokens.
  • Send related calls back to back rather than spread over hours.
  • Log cachedContentTokenCount on every call, so you see a drop the day it happens.

Even set up right, implicit caching is best effort. One team on Google's forum saw only about 4% of input tokens cached on a document pipeline (0.9M of 22.6M), and cost per call went from $0.23 on Gemini 3.8 Flash to $0.88 on Hydrogen.

Use the Batch API for work that can wait

Batch (batchGenerateContent) costs half the standard price, with a 24-hour target turnaround. On Gemini 4 Neon that's $1.50 input, $0.075 cached input and $7.50 output per million tokens. You get the discount whether or not the cache hits, so it's the safest fix for nightly and bulk jobs.

Stay on Gemini 3.8 Flash if you need guaranteed caching

Explicit caching still works on Gemini 3 and 2.5 models, and Google's reply on the forum recommends gemini-3.8-flash for predictable caching (a Stable model with no announced shutdown date). If you send the same big corpus to many calls, that can still be cheaper than any Gemini 4 model.

What it saves

At Google's list price, Gemini 4 Neon charges $3 per million input tokens and $0.15 per million cached input tokens, a 95% discount. Take a pipeline that sends a 20,000-token document plus a 1,000-token question, 10,000 times a month:

  • No cache hits: 210M input tokens × $3 = $630.
  • Document read from cache every time: 200M × $0.15 + 10M × $3 = $60.

Output is the same either way and left out. That's why a caching miss on Gemini 4 can multiply the input bill by ten. And from 1 December 2026, Gemini 4 Argon and Carbon move from $2 / $10 to $4 / $20 per million tokens as their introductory price ends, so a miss on those costs twice as much as before.

FAQ

Does Gemini 4 support context caching?

Only implicit caching. Explicit caching (cachedContents, caches.create) isn't supported on Gemini 4 Argon and newer, including Neon, Carbon and Hydrogen. It still works on Gemini 3 and 2.5 models.

Why is cachedContentTokenCount 0 on Gemini 4 Neon?

Usually the prompt is under 4,096 tokens, something at the start changes between calls, or the calls are too far apart. Implicit caching also isn't guaranteed, so some misses happen even when everything is set up right.

How much is the Gemini 4 cache discount?

Cache hits cost 5% of the normal input price: $0.15 instead of $3 per million tokens on Gemini 4 Neon.

Checklist

  • No caches.create or cached_content left in code that calls a Gemini 4 model?
  • Shared part of the prompt over 4,096 tokens?
  • Shared part first and identical on every call?
  • Reading cachedContentTokenCount (generateContent), not total_cached_tokens?
  • Could this job run through the Batch API instead?

Want someone to check your code for this and the other usual leaks? Get a free cost audit of your repo, or run the free LLM cost audit skill yourself. And see what Gemini 4 Neon costs on each route today.

Sources: Gemini API context caching docs, Gemini API pricing, Google AI developer forum thread on Gemini 4 caching, all checked 30 November 2026.

Pay less for the same models

One URL change. Keep OpenRouter as your backup.

Try SayGM