I’m trying to use client.caches.create()
in the google-genai
Python SDK to cache a large text-only prompt (~2500 tokens). The goal is to optimize cost and performance by avoiding resending this static context repeatedly. Here’s what I do:
from google import genai
from google.genai.types import CreateCachedContentConfig
client = genai.Client(
vertexai=True,
project=credentials.project_id,
location='global',
http_options=HttpOptions(api_version="v1beta1")
cache = client.caches.create(
model="models/gemini-2.0-pro-001",
config=CreateCachedContentConfig(
display_name="aime template test",
system_instruction="Text-only context for moderation",
contents=[Part.from_text("Some instructional prompt text")],
ttl="300s"
)
)
But I consistently get this error:
500 INTERNAL – ResourceCategoryConfig for RESOURCE_CATEGORY_GENAI_CACHE is not found