Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(sse): clamp Gemini thinking budget to model cap (#3842) (#3865)

Diego Rodrigues de Sa e Souza337cd18932e3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c61af02707..dbe445328a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
### 🐛 Fixed
+- **fix(sse): clamp Gemini thinking budget to the model's real cap (`reasoning_effort`/`effort=high` 400)** — translating OpenAI `reasoning_effort=high` (and Claude-Code `output_config.effort=high`) to a Gemini target sent a hardcoded `thinkingBudget: 32768`, which exceeds Flash-tier Gemini's real max of 24576 → upstream HTTP 400 (the `thinkingLevel=high` path already used 24576 and worked on the same model). `gemini-2.5-flash` now declares its real `thinkingBudgetCap` (24576) so the existing `capThinkingBudget()` chokepoint actually clamps, and the Claude→Gemini `output_config.effort` path — which previously sent the raw value with no cap at all — now routes through the same clamp (pro-tier, real cap 32768, is left untouched). ([#3842](https://github.com/diegosouzapw/OmniRoute/issues/3842) — thanks @andrea-kingautomation)
- **fix(intelligence): run pricing + models.dev sync from the live startup path** — like the Arena ELO sync (v3.8.24), the external **pricing sync** (`PRICING_SYNC_ENABLED`) and the **models.dev capability sync** (Settings → AI toggle) were only initialized from `server-init.ts`, which the Next standalone runtime never executes — and models.dev had no caller at all. Their toggles were inert in production. Both are now initialized from `instrumentation-node.ts` (self-gated, opt-in preserved, non-blocking, never fatal). (thanks @diegosouzapw)
- **test(proxy): guard the per-connection 'direct' bypass over a global proxy + clearer label** — the per-connection "Proxy Off" toggle (`proxyEnabled: false`) already overrides a configured **global** proxy (`resolveProxyForConnection` short-circuits to `level: "direct"` before the global step). Added an explicit regression test proving the bypass beats a global assignment (and round-trips on re-enable), and relabeled the UI to "Direct (bypass proxy)" so operators recognize it. Closes the verification gap in [#2996](https://github.com/diegosouzapw/OmniRoute/issues/2996). (thanks @diegosouzapw)
- **feat(connections): per-connection "disable cooldown" opt-out** — a connection can now opt out of the transient cooldown (`providerSpecificData.disableCooling`, with a toggle in the Edit Connection modal). When set, a recoverable failure still records the error/backoff but does **not** take the connection out of rotation, so it stays eligible for selection — useful for a primary key you never want parked on a blip. Terminal states (banned / expired / credits_exhausted) still apply. ([#2997](https://github.com/diegosouzapw/OmniRoute/issues/2997) — thanks @diegosouzapw)
diff --git a/open-sse/translator/request/claude-to-gemini.ts b/open-sse/translator/request/claude-to-gemini.ts
index fda442ea61..92b825f46e 100644
--- a/open-sse/translator/request/claude-to-gemini.ts
+++ b/open-sse/translator/request/claude-to-gemini.ts
@@ -7,7 +7,7 @@ import {
} from "../helpers/geminiHelper.ts";
import { DEFAULT_THINKING_GEMINI_SIGNATURE } from "../../config/defaultThinkingSignature.ts";
import { buildGeminiTools, sanitizeGeminiToolName } from "../helpers/geminiToolsSanitizer.ts";
-import { capMaxOutputTokens } from "../../../src/lib/modelCapabilities.ts";
+import { capMaxOutputTokens, capThinkingBudget } from "../../../src/lib/modelCapabilities.ts";
/**
* Direct Claude → Gemini request translator.
@@ -200,7 +200,13 @@ export function claudeToGeminiRequest(model, body, stream, credentials = null) {
max: 131072,
xhigh: 131072,
};
- const budget = effortBudgetMap[effort];
+ const rawBudget = effortBudgetMap[effort];
+ // #3842: clamp to the model's real thinking-budget cap. This path previously
+ // sent the raw value with no cap, so a Claude-Code client hitting a Flash-tier
+ // Gemini target via output_config.effort="high" sent 32768 (> 24576) → 400.
+ // capThinkingBudget narrows 32768 to e.g. gemini-2.5-flash's 24576 while leaving
+ // pro-tier (real cap 32768) untouched.
+ const budget = rawBudget !== undefined ? capThinkingBudget(model, rawBudget) : undefined;
if (budget !== undefined && budget > 0) {
result.generationConfig.thinkingConfig = {
thinkingBudget: budget,
diff --git a/src/shared/constants/modelSpecs.ts b/src/shared/constants/modelSpecs.ts
index f96f41bac0..7dbd2764c7 100644
--- a/src/shared/constants/modelSpecs.ts
+++ b/src/shared/constants/modelSpecs.ts
@@ -77,6 +77,9 @@ export const MODEL_SPECS: Record<string, ModelSpec> = {
"gemini-2.5-flash": {
maxOutputTokens: 65536,
contextWindow: 1048576,
+ // #3842: real Google max thinking budget for 2.5-flash is 24576; declaring the
+ // cap makes capThinkingBudget() actually clamp instead of passing values through.
+ thinkingBudgetCap: 24576,
supportsThinking: false,
supportsTools: true,
supportsVision: true,
diff --git a/tests/unit/translator-claude-to-gemini.test.ts b/tests/unit/translator-claude-to-gemini.test.ts
index 1252c77dac..70d63f595a 100644
--- a/tests/unit/translator-claude-to-gemini.test.ts
+++ b/tests/unit/translator-claude-to-gemini.test.ts
@@ -251,6 +251,24 @@ test("Claude -> Gemini maps output_config.effort to thinkingConfig when thinking
}
});
+// Regression for #3842: output_config.effort=high must be clamped to a Flash-tier
+// Gemini model's real thinking-budget cap. gemini-2.5-flash's true max is 24576;
+// the previous unclamped 32768 made the upstream return HTTP 400. Pro-tier
+// (gemini-2.5-pro, real cap 32768) is asserted untouched by the test above.
+test("Claude -> Gemini clamps output_config.effort=high to gemini-2.5-flash cap (#3842)", () => {
+ const result = claudeToGeminiRequest(
+ "gemini-2.5-flash",
+ {
+ messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
+ output_config: { effort: "high" },
+ },
+ false
+ );
+ const budget = (result.generationConfig as any).thinkingConfig.thinkingBudget;
+ assert.ok(budget <= 24576, `expected <= 24576 (real cap), got ${budget}`);
+ assert.equal(budget, 24576);
+});
+
test("Claude -> Gemini prefers thinking.budget_tokens over output_config.effort", () => {
const result = claudeToGeminiRequest(
"gemini-2.5-pro",
diff --git a/tests/unit/translator-openai-to-gemini.test.ts b/tests/unit/translator-openai-to-gemini.test.ts
index dcae756f0a..ed22404282 100644
--- a/tests/unit/translator-openai-to-gemini.test.ts
+++ b/tests/unit/translator-openai-to-gemini.test.ts
@@ -1209,9 +1209,29 @@ test("OpenAI -> Gemini request maps reasoning_effort to thinkingConfig", () => {
assert.ok((result as any).generationConfig.thinkingConfig, "expected thinkingConfig");
assert.equal((result as any).generationConfig.thinkingConfig.includeThoughts, true);
+ // gemini-2.0-flash-thinking carries no registry cap, so the raw 32768 base is
+ // passed through unchanged (capThinkingBudget no-ops without a thinkingBudgetCap).
assert.equal((result as any).generationConfig.thinkingConfig.thinkingBudget, 32768);
});
+// Regression for #3842: reasoning_effort=high must not exceed a Gemini model's real
+// thinking-budget cap. gemini-2.5-flash's true upstream max is 24576; sending 32768
+// makes the upstream return HTTP 400. The modelSpecs thinkingBudgetCap now clamps it
+// at the capThinkingBudget chokepoint, matching the thinkingLevel=high path (24576).
+test("OpenAI -> Gemini reasoning_effort=high stays within gemini-2.5-flash cap (#3842)", () => {
+ const result = openaiToGeminiRequest(
+ "gemini-2.5-flash",
+ {
+ messages: [{ role: "user", content: "Solve this complex puzzle" }],
+ reasoning_effort: "high",
+ },
+ false
+ ) as any;
+ const budget = result.generationConfig.thinkingConfig.thinkingBudget;
+ assert.ok(budget <= 24576, `expected <= 24576 (real cap), got ${budget}`);
+ assert.equal(budget, 24576);
+});
+
test("OpenAI -> Gemini request maps google_search tool", () => {
const result = openaiToGeminiRequest(
"gemini-2.0-flash",