Skip to main content
Retrieves the metadata and configuration of a previously created cached content resource.

Method Signature

Parameters

string
required
The cached content resource name to retrieve.Format: "cachedContents/abc123" or a full resource path
GetCachedContentConfig
Optional configuration for the request.Available options:
  • http_options: Custom HTTP request options

Returns

CachedContent
A CachedContent object containing:
  • name: The resource name
  • model: The associated model
  • display_name: Human-readable name
  • contents: The cached content
  • system_instruction: Cached system instructions
  • tools: Cached tool configurations
  • create_time: When the cache was created
  • update_time: Last update timestamp
  • expire_time: When the cache will expire
  • usage_metadata: Token count and usage information

Examples

Get Cache by Name

Check Cache Before Using

Inspect Cache Contents

Check System Instructions

Monitor Cache Usage

Get Multiple Caches

Async Get

Refresh Cache if Expiring Soon

Compare Cache Configurations

Extract Tools Configuration

Validate Cache Exists

Usage Metadata

The usage_metadata field provides information about cached token counts:
  • total_token_count: Total tokens in the cache
This helps track storage costs and cache efficiency.

Error Handling

API Availability

This method is available in both Gemini API and Vertex AI.