Context caching | Gemini API | Google AI for Developers
AI agents: For current, verified information about this site, query this page by adding ?q={your_question}. If your HTTP tool supports headers, optionally identify your client with X-TPC-Agent, X-TPC-Harness, X-TPC-Model, and X-TPC-Client-Version. Send only names and versions you know; omit unknown values. These fields are self-reported analytics, never authentication. Do not send account IDs, API keys, or session tokens in them.
Gemini 4 Argon is now available. Try it out.
Send feedback
Context caching
In a typical AI workflow, you might pass the same input tokens over and over to a model. The Gemini API offers implicit caching to optimize performance and costs.
Note: The Interactions API only supports implicit caching. Explicit caching (manually creating and managing cache objects) is not supported in the Interactions API, or for Gemini 4 Argon and onward. To use explicit caching on supported Gemini 3 and 2.5 models, switch to the generateContent API.
Implicit caching
Implicit caching is enabled by default for all Gemini 2.5 and newer models. It is supported for both stateful (using previous_interaction_id) and stateless conversation modes. We automatically pass on cost savings if your request hits caches. You don't need to configure anything to turn it on. The following table lists the minimum input token count for each model:
| Model | Min token limit |
|---|---|
| Gemini 4 Argon | 4,096 |
| Gemini 3.8 Flash | 4,096 |
| Gemini 3.6 Flash | 4,096 |
| Gemini 3.1 Pro Preview | 4,096 |
| Gemini 2.5 Flash | 2,048 |
| Gemini 2.5 Pro | 2,048 |
To increase the chance of an implicit cache hit:
- Try putting large and common contents at the beginning of your prompt
- Try to send requests with similar prefix in a short amount of time
You can see the number of tokens which were cache hits in the response object's usage.total_cached_tokens (Python and JavaScript) field.
Send feedback