[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3

How Context Caching Works

🗄️ Context Caching 15m 300 BASE XP⌨ HANDS-ON LAB

Slashing Costs by 70%

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 70% lower input token costs.
  • Near-instant time-to-first-token (TTFT).
from vertexai.preview import caching

# Cache a massive 1-hour video (minimum 32k tokens required)
cache = caching.CachedContent.create(
    model_name="gemini-3.1-pro-001",
    system_instruction="You are a video analyst.",
    contents=[video_part],
    ttl=datetime.timedelta(minutes=60)
)

Implicit Caching (Gemini 2.5+)

Implicit Caching is automatically enabled on Gemini 2.5 and later models. Unlike explicit Context Caching (which requires creating a cache object), implicit caching detects repeated prompt prefixes across requests and caches them transparently — with up to a ~90% discount on cached input tokens. No code changes are needed; simply ensure your requests share a common prefix (system instructions, large context) and implicit caching kicks in automatically.

⌨ HANDS-ON LABCreate & List a Context Cache
⭐ +150 XP

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.

1Capture a fresh access token in the TOKEN shell variable.
2POST to the cachedContents endpoint to create a cache with a model, contents, and a ttl.
3GET the same cachedContents endpoint to list your active caches.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 3 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 2
What is the primary benefit of Context Caching in Vertex AI?
It trains the model on your data
It significantly reduces latency and cost when repeatedly querying massive prompts
It generates better images
It automatically translates the prompt into 50 languages