Skip to content

Commit 1ec6b15

Browse files
anandgupta42claude
andauthored
fix: use thinking levels for Gemini 4 small calls (AltimateAI#1534)
* fix: use thinking levels for Gemini 4 small calls `smallOptions` gave every Google reasoning model except Gemini 3 `thinkingBudget: 0`. Gemini 4 rejects budgets with a 400 ("Thinking budget is not supported for this model. Use thinking level instead."), so every small call (session title, prompt enhancement, project copy) failed on it. - Gemini 2.x and unversioned aliases keep `thinkingBudget: 0`; Gemini 3 keeps `thinkingLevel: "minimal"`; Gemini 4+ uses the lowest configured supported level, falling back to `low`. - Tests cover Google and Vertex for 2.0/2.5/3/3.1/4/5/30 and an unversioned alias, with and without generated variants. Closes AltimateAI#1533 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: keep the substring rule for Gemini 3 ids without a parseable generation Ids such as `vertex_gemini-3pro` matched the earlier `includes("gemini-3")` check but not the generation regex, so they fell back to `thinkingBudget: 0`. Adds prefixed, dated-preview and unparseable id cases. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: parse the Gemini generation from any `gemini-<N>` id form Prefixed or concatenated ids such as `vertex_gemini-4argon` did not match the anchored pattern, so they fell back to `thinkingBudget: 0` and the 400. One unanchored `gemini-(\d+)` parse now covers Gemini 3 and Gemini 4+ alike, which also replaces the substring fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 05cc4d1 commit 1ec6b15

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,18 +1347,27 @@ export namespace ProviderTransform {
13471347
) {
13481348
return mergeDeep({ store: false }, small)
13491349
}
1350-
// altimate_change start — upstream_fix: restore Google minimal thinking for small calls only on reasoning models
1350+
// altimate_change start — upstream_fix: use generation-supported Google thinking controls for small reasoning calls
13511351
if (
13521352
(model.providerID === "google" ||
13531353
model.api.npm === "@ai-sdk/google" ||
13541354
model.api.npm === "@ai-sdk/google-vertex") &&
13551355
model.capabilities.reasoning
13561356
) {
13571357
const id = model.api.id.toLowerCase()
1358-
if (id.includes("gemini-3")) {
1358+
// Leading digits after "gemini-", wherever it appears (prefixed, concatenated or dated ids).
1359+
const generation = Number(/gemini-(\d+)/.exec(id)?.[1])
1360+
if (generation === 3) {
13591361
return { thinkingConfig: { thinkingLevel: "minimal" } }
13601362
}
1361-
return { thinkingConfig: { thinkingBudget: 0 } }
1363+
// Gemini 2.x and unversioned aliases (e.g. gemini-flash-latest) keep the budget control.
1364+
if (!(generation >= 4)) {
1365+
return { thinkingConfig: { thinkingBudget: 0 } }
1366+
}
1367+
// Gemini 4+ rejects budgets and "minimal"; prefer the lowest configured supported level.
1368+
const levels = Object.values(model.variants ?? {}).map((variant) => variant.thinkingConfig?.thinkingLevel)
1369+
const thinkingLevel = WIDELY_SUPPORTED_EFFORTS.find((level) => levels.includes(level)) ?? "low"
1370+
return { thinkingConfig: { thinkingLevel } }
13621371
}
13631372
// altimate_change end
13641373
if (model.providerID === "openrouter" || model.providerID === "llmgateway") {

‎packages/opencode/test/provider/transform.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,55 @@ describe("ProviderTransform.smallOptions - google thinking", () => {
307307
variants: overrides.variants ?? {},
308308
}) as any
309309

310+
// altimate_change start — small calls must use thinking controls supported by each Gemini generation
311+
for (const provider of [
312+
{ providerID: "google", npm: "@ai-sdk/google" },
313+
{ providerID: "google-vertex", npm: "@ai-sdk/google-vertex" },
314+
] as const) {
315+
for (const testCase of [
316+
{ id: "gemini-2.0-flash", thinkingConfig: { thinkingBudget: 0 } },
317+
{ id: "gemini-2.5-flash", thinkingConfig: { thinkingBudget: 0 } },
318+
{ id: "gemini-3-pro", thinkingConfig: { thinkingLevel: "minimal" } },
319+
{ id: "gemini-3.1-pro", thinkingConfig: { thinkingLevel: "minimal" } },
320+
{ id: "models/gemini-3-pro-preview", thinkingConfig: { thinkingLevel: "minimal" } },
321+
{ id: "vertex_gemini-3pro", thinkingConfig: { thinkingLevel: "minimal" } },
322+
{ id: "vertex_gemini-4argon", thinkingConfig: { thinkingLevel: "low" } },
323+
{ id: "publishers/google/models/gemini-4-argon", thinkingConfig: { thinkingLevel: "low" } },
324+
{ id: "gemini-2.5-flash-lite-preview-06-17", thinkingConfig: { thinkingBudget: 0 } },
325+
{ id: "gemini-4-argon", thinkingConfig: { thinkingLevel: "low" } },
326+
{ id: "gemini-5-pro", thinkingConfig: { thinkingLevel: "low" } },
327+
{ id: "gemini-30-pro", thinkingConfig: { thinkingLevel: "low" } },
328+
{ id: "gemini-flash-latest", thinkingConfig: { thinkingBudget: 0 } },
329+
]) {
330+
for (const configured of [false, true]) {
331+
test(`${provider.providerID} ${testCase.id} uses supported small thinking controls with ${configured ? "generated" : "empty"} variants`, () => {
332+
const model = createGoogleModel(testCase.id, provider)
333+
if (configured) model.variants = ProviderTransform.variants(model)
334+
335+
const result = ProviderTransform.smallOptions(model)
336+
337+
expect(result).toEqual({ thinkingConfig: testCase.thinkingConfig })
338+
if (testCase.thinkingConfig.thinkingLevel) {
339+
expect(result.thinkingConfig).not.toHaveProperty("thinkingBudget")
340+
}
341+
})
342+
}
343+
}
344+
345+
test(`${provider.providerID} uses the lowest configured Gemini 4 thinking level regardless of variant names or order`, () => {
346+
const model = createGoogleModel("gemini-4-argon", {
347+
...provider,
348+
variants: {
349+
detailed: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
350+
balanced: { thinkingConfig: { includeThoughts: true, thinkingLevel: "medium" } },
351+
},
352+
})
353+
354+
expect(ProviderTransform.smallOptions(model)).toEqual({ thinkingConfig: { thinkingLevel: "medium" } })
355+
})
356+
}
357+
// altimate_change end
358+
310359
test("disables Gemini 2.5 thinking budget for small calls even when high is the first variant", () => {
311360
const result = ProviderTransform.smallOptions(
312361
createGoogleModel("gemini-2.5-pro", {

0 commit comments

Comments
 (0)