Skip to content

Commit bfc1071

Browse files
committed
fix: remove explicit cache_control for Google models in OpenRouter (#4487)
- Remove all Google models from OPEN_ROUTER_PROMPT_CACHING_MODELS set - This resolves 3+ minute lag when using google/gemini-2.5-pro-preview - OpenRouter still provides automatic implicit ephemeral caching for these models - Updated tests to handle intentional exclusion of Google models from explicit caching Fixes #4487
1 parent 483d951 commit bfc1071

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

packages/types/src/providers/openrouter.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ export const OPEN_ROUTER_PROMPT_CACHING_MODELS = new Set([
3939
"anthropic/claude-3.7-sonnet:thinking",
4040
"anthropic/claude-sonnet-4",
4141
"anthropic/claude-opus-4",
42-
"google/gemini-2.5-pro-preview",
43-
"google/gemini-2.5-flash-preview",
44-
"google/gemini-2.5-flash-preview:thinking",
45-
"google/gemini-2.5-flash-preview-05-20",
46-
"google/gemini-2.5-flash-preview-05-20:thinking",
47-
"google/gemini-2.0-flash-001",
48-
"google/gemini-flash-1.5",
49-
"google/gemini-flash-1.5-8b",
5042
])
5143

5244
// https://www.anthropic.com/news/3-5-models-and-computer-use

src/api/providers/fetchers/__tests__/openrouter.spec.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,37 @@ describe("OpenRouter API", () => {
2323

2424
const models = await getOpenRouterModels()
2525

26-
expect(
27-
Object.entries(models)
28-
.filter(([_, model]) => model.supportsPromptCache)
29-
.map(([id, _]) => id)
30-
.sort(),
31-
).toEqual(Array.from(OPEN_ROUTER_PROMPT_CACHING_MODELS).sort())
26+
// Check that our caching models list is a subset of what OpenRouter supports
27+
// (we may intentionally exclude some models that support caching)
28+
const openRouterSupportedCaching = Object.entries(models)
29+
.filter(([_, model]) => model.supportsPromptCache)
30+
.map(([id, _]) => id)
31+
32+
const ourCachingModels = Array.from(OPEN_ROUTER_PROMPT_CACHING_MODELS)
33+
34+
// Verify all our caching models are actually supported by OpenRouter
35+
for (const modelId of ourCachingModels) {
36+
expect(openRouterSupportedCaching).toContain(modelId)
37+
}
38+
39+
// Check that we have the expected models (excluding intentionally excluded ones)
40+
const excludedCachingModels = new Set([
41+
// All Google models intentionally excluded from caching
42+
"google/gemini-2.5-pro-preview",
43+
"google/gemini-2.0-flash-001",
44+
"google/gemini-2.5-flash-preview",
45+
"google/gemini-2.5-flash-preview-05-20",
46+
"google/gemini-2.5-flash-preview-05-20:thinking",
47+
"google/gemini-2.5-flash-preview:thinking",
48+
"google/gemini-flash-1.5",
49+
"google/gemini-flash-1.5-8b",
50+
])
51+
52+
const expectedCachingModels = openRouterSupportedCaching
53+
.filter((id) => !excludedCachingModels.has(id))
54+
.sort()
55+
56+
expect(ourCachingModels.sort()).toEqual(expectedCachingModels)
3257

3358
expect(
3459
Object.entries(models)

0 commit comments

Comments
 (0)