google · Google AI Docs
Google AI API Caching
Explains how to use context caching to save and reuse precomputed input tokens for repeated queries against the same media or large datasets to reduce latency and costs.
Derived skill
Files assembled from official documentation
Viewing SKILL.md
Google AI API Caching
Explains how to use context caching to save and reuse precomputed input tokens for repeated queries against the same media or large datasets to reduce latency and costs.
When To Use
Use when you need to reduce costs and latency when performing multiple different queries against the same large media file or extensive context window.
Reference Files
| File | Contains | Use For |
|---|---|---|
SKILL.md | Entry point: scope, routing table, and workflow. | Start here. |
docs/google-ai-api-caching-workflow-guide.md | An example request body and endpoint details for creating a cached content resource using the Google AI API. | Questions about an example request body and endpoint details for creating a cached content resource using the Google AI API. |
examples/google-ai-api-caching-google-ai-api-python-context-caching.text | A Python code snippet demonstrating how to upload a file and create a cached content object using the Google GenAI SDK. | Exact payloads, commands, or snippets shown in A Python code snippet demonstrating how to upload a file and create a cached content object using the Google GenAI SDK. |
examples/google-ai-api-caching-google-ai-api-context-caching-nodejs.text | A Node.js code example demonstrating how to upload a file and create a context cache using the Google AI SDK. | Exact payloads, commands, or snippets shown in A Node.js code example demonstrating how to upload a file and create a context cache using the Google AI SDK. |
examples/google-ai-api-caching-go-context-client-setup.text | A Go code snippet demonstrating how to initialize a Gemini API client and prepare a context for content caching operations. | Exact payloads, commands, or snippets shown in A Go code snippet demonstrating how to initialize a Gemini API client and prepare a context for content caching opera... |
examples/google-ai-api-caching-context-caching-request-json.text | A JSON request body demonstrating how to create a context cache for a Gemini model using inlined text data and system instructions. | Exact payloads, commands, or snippets shown in A JSON request body demonstrating how to create a context cache for a Gemini model using inlined text data and system... |
examples/google-ai-api-caching-google-ai-api-python-context-caching-2.text | A Python code example demonstrating how to upload a file and create a cached content object using the Google GenAI SDK. | Exact payloads, commands, or snippets shown in A Python code example demonstrating how to upload a file and create a cached content object using the Google GenAI SDK. |
examples/google-ai-api-caching-nodejs-upload.text | A Node.js code example demonstrating how to upload a file to the Google AI API to prepare for context caching. | Exact payloads, commands, or snippets shown in A Node.js code example demonstrating how to upload a file to the Google AI API to prepare for context caching. |
examples/google-ai-api-caching-go-context-client-initialization.text | A Go code snippet demonstrating how to initialize a Gemini API client and prepare a context for content caching operations. | Exact payloads, commands, or snippets shown in A Go code snippet demonstrating how to initialize a Gemini API client and prepare a context for content caching opera... |
examples/google-ai-api-caching-python-client-setup.text | A Python code example demonstrating how to initialize a GenAI client and create a chat session with system instructions for context caching. | Exact payloads, commands, or snippets shown in A Python code example demonstrating how to initialize a GenAI client and create a chat session with system instructio... |
examples/google-ai-api-caching-nodejs-context-caching.text | A Node.js code example demonstrating how to implement context caching using the Google Generative AI SDK. | Exact payloads, commands, or snippets shown in A Node.js code example demonstrating how to implement context caching using the Google Generative AI SDK. |
examples/google-ai-api-caching-go-context-client-initialization-2.text | A Go code snippet demonstrating how to initialize a Gemini API client with context and system instructions for content caching. | Exact payloads, commands, or snippets shown in A Go code snippet demonstrating how to initialize a Gemini API client with context and system instructions for conten... |
examples/google-ai-api-caching-python-client-create-cache.text | A Python script demonstrating how to upload a file and create a context cache using the Google GenAI client. | Exact payloads, commands, or snippets shown in A Python script demonstrating how to upload a file and create a context cache using the Google GenAI client. |
examples/google-ai-api-caching-nodejs-upload-2.text | A Node.js code example demonstrating how to upload a file using the Google AI SDK to prepare for context caching. | Exact payloads, commands, or snippets shown in A Node.js code example demonstrating how to upload a file using the Google AI SDK to prepare for context caching. |
examples/google-ai-api-caching-go-context-client-initialization-3.text | A Go code snippet demonstrating how to initialize a Gemini API client and prepare a context for content caching operations. | Exact payloads, commands, or snippets shown in A Go code snippet demonstrating how to initialize a Gemini API client and prepare a context for content caching opera... |
examples/google-ai-api-caching-curl-request.text | A curl command used to retrieve information about a specific Google AI API cache resource. | Exact payloads, commands, or snippets shown in A curl command used to retrieve information about a specific Google AI API cache resource. |
examples/google-ai-api-caching-google-ai-api-python-context-caching-3.text | A Python code snippet demonstrating how to upload a file and create a context cache using the Google GenAI SDK. | Exact payloads, commands, or snippets shown in A Python code snippet demonstrating how to upload a file and create a context cache using the Google GenAI SDK. |
examples/google-ai-api-caching-nodejs-upload-3.text | A Node.js code example demonstrating how to upload a file to the Google AI API for use with context caching. | Exact payloads, commands, or snippets shown in A Node.js code example demonstrating how to upload a file to the Google AI API for use with context caching. |
examples/google-ai-api-caching-go-context-setup.text | A Go code snippet demonstrating client initialization and context setup for using the Google AI API caching feature. | Exact payloads, commands, or snippets shown in A Go code snippet demonstrating client initialization and context setup for using the Google AI API caching feature. |
examples/google-ai-api-caching-update-ttl-curl.text | A curl command demonstrating how to update the time-to-live (TTL) setting for an existing Google AI API cache. | Exact payloads, commands, or snippets shown in A curl command demonstrating how to update the time-to-live (TTL) setting for an existing Google AI API cache. |
examples/google-ai-api-caching-python-create-delete-cache.text | A Python script demonstrating how to upload a file, create a context cache with system instructions, and subsequently delete the cache using the Google GenAI SDK. | Exact payloads, commands, or snippets shown in A Python script demonstrating how to upload a file, create a context cache with system instructions, and subsequently... |
examples/google-ai-api-caching-nodejs-upload-4.text | A Node.js code example demonstrating how to upload a file to the Google AI API for use with context caching. | Exact payloads, commands, or snippets shown in A Node.js code example demonstrating how to upload a file to the Google AI API for use with context caching. |
examples/google-ai-api-caching-delete-cache-curl.text | A shell script using curl to delete a specific context cache from the Google AI API. | Exact payloads, commands, or snippets shown in A shell script using curl to delete a specific context cache from the Google AI API. |
examples/google-ai-api-caching-json.text | A JSON schema object demonstrating the structure for Google AI API caching configurations. | Exact payloads, commands, or snippets shown in A JSON schema object demonstrating the structure for Google AI API caching configurations. |
What This Skill Covers
- Context caching allows you to save and reuse precomputed input tokens that you wish to use repeatedly, for example when asking different questions about the...
- Main sections:
Method: cachedContents.create,Endpoint,Request body,Example request,Basic.
Workflow
- Open the most relevant file under
docs/for the exact documented workflow and wording. - Open
schemas/files for exact structured contracts. - Open
examples/files for concrete requests, commands, snippets, and manifests. - Do not add behavior or configuration that is not present in the attached source files.
Canonical source: https://ai.google.dev/api/caching
