一键导入
continue-gemini-explicit
Continue's Gemini provider doesn't use the cachedContents API at all. Add explicit caching for sessions over the minimum token threshold.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Continue's Gemini provider doesn't use the cachedContents API at all. Add explicit caching for sessions over the minimum token threshold.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Aider uses 5min TTL by default and works around long pauses with keepalive pings. Wire up the 1h TTL beta instead.
Aider's --cache-prompts is off by default. Flip it on for supported models.
Stop Cline from burning a cache breakpoint on the volatile current user message every turn.
Cline OpenAI native provider sends no prompt_cache_key. Add a stable per-task key so cached_tokens stops being zero.
Cline's system prompt includes a timestamp that may be recomputed per request, invalidating the system-prompt cache.
Continue's prompt caching is opt-in via config and off by default. Flip the default to systemAndTools.
| name | continue-gemini-explicit |
| description | Continue's Gemini provider doesn't use the cachedContents API at all. Add explicit caching for sessions over the minimum token threshold. |
| target_harness | Continue |
| target_repo | continuedev/continue |
| target_files | ["packages/openai-adapters/src/apis/Gemini.ts"] |
| target_commit | main (last push 2026-05-26) |
| estimated_savings | 75% input discount on Gemini Pro / 50% on Flash for sessions above the min-token threshold |
packages/openai-adapters/src/apis/Gemini.ts in continuedev/continue.
The Gemini provider class does not use the cachedContents API at
all. Gemini 2.5+ has implicit caching that fires automatically for
byte-stable prefixes (free, best-effort), but explicit cachedContents
gives guaranteed cost reduction (0.25x input price on Pro) and
controllable TTL. Continue leaves this entire mechanism unused.
Result: long-running Gemini sessions with the same system prompt + tools (the exact use case caching is for) get only implicit-cache luck, not the guaranteed 75% discount.
Add a _maybeCreateCache helper and reuse the cached content across
calls within a session:
--- a/packages/openai-adapters/src/apis/Gemini.ts
+++ b/packages/openai-adapters/src/apis/Gemini.ts
@@
export class GeminiApi implements BaseLlmApi {
apiBase: string = "https://generativelanguage.googleapis.com/v1beta/";
private genAI: GoogleGenAI;
+ private cacheName: string | null = null;
+ private cacheSystemHash: string | null = null;
@@
+ private estimateTokens(text: string): number {
+ // Conservative ~4 chars/token; fine for threshold gating
+ return Math.ceil(text.length / 4);
+ }
+
+ private async _maybeCreateCache(
+ systemInstruction: string,
+ tools?: any[],
+ ): Promise<string | null> {
+ if (!systemInstruction) return null;
+
+ // Min tokens: 4096 for Pro variants, 1024 for Flash
+ const isPro = this.config.model.toLowerCase().includes("pro");
+ const minTokens = isPro ? 4096 : 1024;
+ if (this.estimateTokens(systemInstruction) < minTokens) return null;
+
+ // Dedupe: only create a cache if system has changed
+ const hash = crypto.createHash("sha256")
+ .update(systemInstruction + JSON.stringify(tools ?? []))
+ .digest("hex").slice(0, 16);
+ if (this.cacheName && this.cacheSystemHash === hash) {
+ return this.cacheName;
+ }
+
+ try {
+ const cache = await this.genAI.caches.create({
+ model: `models/${this.config.model}`,
+ config: {
+ systemInstruction,
+ tools,
+ ttl: "3600s", // 1 hour
+ },
+ });
+ this.cacheName = cache.name ?? null;
+ this.cacheSystemHash = hash;
+ return this.cacheName;
+ } catch (e) {
+ // Cache creation can fail (e.g. content under min). Fall back
+ // to implicit caching by returning null.
+ return null;
+ }
+ }
Then in the generateContent call path:
+ const cachedContent = await this._maybeCreateCache(
+ systemInstruction,
+ tools,
+ );
+
const response = await this.genAI.models.generateContent({
model: this.config.model,
contents: messages,
+ config: cachedContent
+ ? { cachedContent }
+ : undefined,
});
gemini-2.5-pro or gemini-3-pro-preview
and a system prompt over 4096 tokens (or load a big AGENTS.md).POST /v1beta/cachedContents create call
followed by a generateContent call referencing the cache name.generateContent, reusing the same
cachedContent reference.usageMetadata.cachedContentTokenCount —
should be > 0 on both calls.Gemini has two caching paths: implicit (automatic, free, best-effort)
and explicit (cachedContents API, guaranteed discount, configurable
TTL, costs storage per hour). For agent loops with a stable large
system prompt, explicit is strictly better — you trade pennies of
storage for dollars of discount.
Minimums:
Below threshold, caches.create() returns 400 — the fallback to
implicit (return null) handles this gracefully.
See docs/concepts/gemini.md. Full audit: audits/continue.md.