◉GEMINI LABJP
●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…
Articles/API / SDK
◈ API / SDK/2026-03-24Advanced

Gemini API Context Caching— Cut Document Processing Costs by 90%

Learn how to use Gemini API's context caching to reduce repetitive document processing costs by up to 90%. Includes Python SDK implementation, caching strategies, and cost calculations.

Gemini API249Context Caching5Cost Optimization13Python51PremiumLarge-Scale Processing

✦ Premium Article

Setup and context: Why Context Caching Matters

When running Gemini API in production, the biggest cost driver is repeatedly sending large contexts. For instance, if you need to answer 100 questions about a 500-page technical manual, including the entire manual in every prompt leads to enormous token consumption.

Gemini API's Context Caching feature lets you cache large contexts once and reuse them across multiple requests, reducing input token costs by up to 90%.

What you'll learn:

  • How context caching works and its pricing model
  • Creating, using, and managing caches with the Python SDK
  • Cost optimization strategies for large document processing
  • Cache design patterns for production environments

How Context Caching Works

Basic Architecture

Context caching temporarily stores large contexts (documents, system prompts, code, etc.) on Google's servers. Subsequent requests reference a cache ID instead of re-sending the full context.

Standard request flow:

Request 1: [500-page manual] + Question 1 → Answer 1
Request 2: [500-page manual] + Question 2 → Answer 2
Request 3: [500-page manual] + Question 3 → Answer 3
→ Manual tokens are billed every single time

With caching:

Cache creation: [500-page manual] → Cache ID
Request 1: [Cache ID] + Question 1 → Answer 1 (cached tokens at discount)
Request 2: [Cache ID] + Question 2 → Answer 2 (cached tokens at discount)
Request 3: [Cache ID] + Question 3 → Answer 3 (cached tokens at discount)

Pricing

Context cache input tokens are priced at approximately 75% less than standard input tokens (as of March 2026).

ItemStandard InputCached InputSavings
Gemini 2.5 Pro$1.25/MTok$0.3125/MTok75%
Gemini 2.5 Flash$0.075/MTok$0.01875/MTok75%

Note: MTok = 1 million tokens. Cache storage costs ($4.50/MTok/hour for Pro) apply separately.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Cost optimization for Gemini API calls using Context Caching
✦Cost reduction patterns for large-scale text processing
✦Best practices for caching strategies
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

◈ API / SDK2026-10-14
When Your config Raises "Extra inputs are not permitted", Check the Spelling of Every Key
If a google-genai call fails with a pydantic ValidationError (extra_forbidden) the moment you pass a config, it is almost always a one-letter typo. Here is the output I reproduced, a small function that checks keys before the call, and how to tell why response.text came back as None.
◈ API / SDK2026-10-08
When a Deprecation Has No Shutdown Date: Re-Picking an Image Model on Three Conditions
gemini-nano-banana-2.1 went GA on October 6, and gemini-3.1-flash-image was deprecated with no shutdown date. Here is a table and a short script for choosing a replacement by resolution, reference images, and search grounding.
◈ API / SDK2026-09-22
When Function Calls Turn Into Plain Text, Suspect the Property Names in Your Tool Declarations
A record of chasing MALFORMED_FUNCTION_CALL after output limits and schema conflicts were ruled out, bisecting nine tool declarations down to one property name, and adding a linter that stops bad names before they ship.