How Context Caching Works — Context Caching
How Context Caching Works
Slashing Costs by Up to 90%–95%
When you cache a large prompt (like a codebase or a 1-hour video), Google processes the input and stores the Key-Value (KV) cache in memory.
Subsequent queries against that cached content skip the initial processing phase. This results in:
- Up to 90% off cached input tokens on Gemini 3.8 Flash ($0.075/MTok) and 95% off on Gemini 4 Argon ($0.10/MTok promo, $0.20/MTok standard).
- Near-instant time-to-first-token (TTFT).
from google import genai
from google.genai import types
client = genai.Client(vertexai=True, project="my-project", location="us-central1")
# Explicit cache on Gemini 3.8 Flash (minimum 4,096 tokens required)
cache = client.caches.create(
model="gemini-3.8-flash",
config=types.CreateCachedContentConfig(
system_instruction="You are a video analyst.",
contents=[video_part],
ttl="3600s"
)
)
Implicit vs Explicit Caching (Gemini 3.x & Gemini 4 Argon)
Implicit Caching is enabled by default across Gemini 3.x and Gemini 4 Argon with zero hourly storage fees (persisting up to 24 hours). Shared prompt prefixes meeting the minimum threshold (4,096–6,144 tokens; plus ≥2,050 new tokens per turn in Argon multi-turn loops) automatically receive a 90%–95% input token discount. Critical API Rule: gemini-4-argon and the Interactions API support implicit caching only — explicit cachedContents objects (with TTL-governed storage billing) are supported specifically on Gemini 3.x models such as gemini-3.8-flash and gemini-3.6-flash.
Your team queries the same 500-page contract hundreds of times a day. Create a cachedContents resource over REST, then list active caches to confirm it exists.