SPB Git

Repository Public

caching.md 1.6 KB 32 lines markdown

1In a typical AI workflow, you might pass the same input tokens over and over to2a model. The Gemini API offers implicit caching to optimize performance and costs.34> [!NOTE]5> **Note:** The **Interactions API** only supports implicit caching. Explicit caching (manually creating and managing cache objects) is not supported in the Interactions API. To use explicit caching, switch to the [generateContent API](https://ai.google.dev/gemini-api/docs/generate-content/caching).67## Implicit caching89Implicit caching is enabled by default for all Gemini 2.5 and newer models. It is10supported for both [stateful](https://ai.google.dev/gemini-api/docs/text-generation#multi-turn-conversations) (using `previous_interaction_id`)11and [stateless](https://ai.google.dev/gemini-api/docs/text-generation#stateless-conversations) conversation modes.12We automatically pass on cost savings if your request hits caches. There is nothing you need to do13in order to enable this. The minimum input14token count for context caching is listed in the following table for each model:1516| Model | Min token limit |17|---|---|18| Gemini 3.8 Flash | 4,096 |19| Gemini 3.7 Flash | 4,096 |20| Gemini 3.6 Flash | 4,096 |21| Gemini 3.5 Flash | 4,096 |22| Gemini 3.1 Pro Preview | 4,096 |23| Gemini 2.5 Flash | 2,048 |24| Gemini 2.5 Pro | 2,048 |2526To increase the chance of an implicit cache hit:2728- Try putting large and common contents at the beginning of your prompt29- Try to send requests with similar prefix in a short amount of time3031You can see the number of tokens which were cache hits in the response object's32`usage.total_cached_tokens` (Python and JavaScript) field.
Files main
Menu

Theme