Skip to main content
Deletes a cached content resource. This frees up storage and stops billing for the cached tokens.

Method Signature

Parameters

string
required
The cached content resource name to delete.Format: "cachedContents/abc123"
DeleteCachedContentConfig
Optional configuration for the request.Available options:
  • http_options: Custom HTTP request options

Returns

DeleteCachedContentResponse
A response object confirming the deletion.Contains:
  • sdk_http_response: HTTP response metadata

Examples

Delete Cache

Delete After Use

Delete Multiple Caches

Delete Old Caches

Delete All Caches

Async Delete

Delete with Verification

Context Manager Pattern

Delete Expiring Caches

Cleanup by Display Name Pattern

Batch Delete with Results

Delete Cache After Session

Cost Optimization

Deleting caches when no longer needed:
  • Stops billing for cached token storage
  • Frees up cache quota
  • Prevents accidental use of outdated cached content
Best practice: Delete caches immediately after use if they won’t be reused.

Error Handling

Important Notes

  • Once deleted, a cache cannot be recovered
  • Deletion is immediate and permanent
  • Active requests using the cache may fail
  • Delete caches before they’re needed to avoid errors
Caches are automatically deleted when they expire, so manual deletion is optional. However, deleting unused caches early can reduce costs.

API Availability

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