Gemini prompt cache
Skill baronguyen001/ai-automation-skills/skills/gemini-prompt-cache
8 production-tested Claude skills: automation, Gemini cost/structured output, OSS bounty scouting, ML validation.
npx -y skills add baronguyen001/ai-automation-skills --skill gemini-prompt-cacheAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Cache a long, stable Gemini system-prompt prefix once and reuse the handle across many calls so repeated instruction tokens bill at the cheaper cached rate instead of full input. Use for cache gemini system prompt, context caching, cut gemini input cost, cachedContent, or reuse a long prompt prefix.
SKILL.md
2.5 KB, 502 tokens by cl100k_base, as published. Nobody here has run it
Gemini Prompt Cache
Use this skill when the same large instruction block - rules, a response schema, few-shot examples - is sent on every Gemini request. Caching that prefix once turns those repeated input tokens into a much cheaper cached-token rate, which matters a lot at volume. This wraps Gemini context caching: create the cache once, then point every generate call at the cached handle.
When to invoke
- User says: "cache my gemini system prompt" / "cut gemini input cost" / "context caching" / "reuse a long prompt prefix"
- Code in the conversation uses: a fixed multi-thousand-token system instruction repeated across many
generate_contentcalls.
When NOT to invoke
- The system prompt is short, or it changes on every call (caching a one-off prefix loses money on the cache write).
- The user wants output-side savings (use [[gemini-flash-budget]] to drop thinking tokens instead).
Concrete example
User input:
I send the same 4k-token extraction ruleset to Gemini on every row. Stop paying full price for it.
Output:
# Copy assets/cache.py into your project, then:
from cache import create_cache, generate_with_cache
prefix = create_cache(BIG_RULESET, model="gemini-2.5-flash", ttl_seconds=1800)
for row in rows:
print(generate_with_cache(prefix, row)) # ruleset billed at cached rate
The helper reads GEMINI_API_KEY from the environment and requires google-genai.
Pattern to apply
- Separate the stable prefix (rules, schema, examples) from the per-call user text.
- Create the cache once with
caches.create, storing the returned handle and a TTL. - On each call, pass
cached_content=<handle>so only the user text is billed at full input rate. - Match the TTL to your batch duration; a too-short TTL forces re-creation, a too-long one wastes storage.
- Track the savings with [[gemini-cost-tracker]] to confirm the cache is paying off.
Reference: assets/cache.py.
Source
Distilled from production use across the author's automation projects. v1.0.0. See also: [[gemini-flash-budget]], [[gemini-cost-tracker]].
→ Build the full runnable bot with Trawlkit.