magpie icon indicating copy to clipboard operation
magpie copied to clipboard

gateway: Gemini via OpenRouter still spends a small max_tokens on thinking (sibling of 8bed54271)

Open yetone opened this issue 1 week ago • 2 comments

Sibling left by 8bed54271 (v0.1.4815, fwxkogaia on X).

8bed54271 gives Gemini 2.5+ thinking room above a small reply limit (≤16384, no reasoning asked, no user Max output) when the provider is Google itself (AI Studio, Vertex AI, Google sign-in). Two cases still fail the same way:

  1. OpenRouter's Gemini. Left as it comes because OpenRouter holds the whole max_tokens against the balance, so a raised limit could get a low-balance request refused. A client sending max_tokens 8192 with no reasoning can still get every token spent on thinking and an empty reply (502 "whole output spent on reasoning"). Options: ask OpenRouter for a low/none reasoning effort instead of raising the limit, or raise only when the balance allows.
  2. Nowledge Mem's 60-second timeout. With the room raised, a long high-level thinking pass can now outlast Mem's client timeout.

Neither was reproduced against a real account; both come from reading the code paths in internal/gateway/maxoutput.go.

yetone avatar Nov 25 '26 20:11 yetone

A clean upstream-based branch is available: L0NE-6/magpie-fix/7763-7765-free-models-upstream-v2 (commit 6332e77e), with the prerequisite quota-cut fix d8b71458. It keeps vendor-free models through Cline/Kilo/OpenRouter cards and caps OpenRouter Gemini thinking with reasoning.effort=low. Focused agent/gateway/provider tests and go vet pass. The full Windows provider package still has the unrelated TestRestartSwitchedCodexAppReal host limitation.

L0NE-6 avatar Nov 26 '26 01:11 L0NE-6

Fix on the fork, one commit, based on origin/main 6346f3835:

https://github.com/yetone/magpie/compare/main...joei4cm:magpie:fix/7763-openrouter-gemini-low-effort

Small-limit request to a Gemini that thinks by default at OpenRouter, naming no reasoning, is asked for reasoning at low instead of a raised max_tokens — reasoning_effort (OpenRouter's shorthand for reasoning.effort, which a Gemini 3 reads as its thinking level and a 2.5 as a budget) on Chat, reasoning.effort on Responses, thinking at the least budget of 1024 on Messages. Low rather than off, since reasoning is mandatory on these models and "none" is refused. The limit itself goes as named, so nothing extra is held against the balance.

TestOpenRouterGeminiAskedLowEffort (fake upstream): Chat max_tokens/max_completion_tokens, a 2.5 Pro, a Responses and a Messages client all go out at low with the limit as named; effort or reasoning asked, the user's Max output, a large limit, no limit, a Flash-Lite, a non-Gemini model and a relay's Gemini are unchanged. Red on the same test against maxoutput.go at origin/main.

Run: gofmt; go vet -tags nogui ./internal/gateway; the new test and its siblings green, once under -race. The full suite was not run. Not tried against a real OpenRouter account. Mem's 60s timeout (the issue's second case) is left as it is.

joei4cm avatar Nov 26 '26 04:11 joei4cm