Skip to content

fix: convert thinkingLevel to thinkingBudget for v1internal compatibility#2095

Open
thebtf wants to merge 1 commit intolbjlaq:mainfrom
thebtf:fix/thinking-level-conversion
Open

fix: convert thinkingLevel to thinkingBudget for v1internal compatibility#2095
thebtf wants to merge 1 commit intolbjlaq:mainfrom
thebtf:fix/thinking-level-conversion

Conversation

@thebtf
Copy link
Copy Markdown

@thebtf thebtf commented Feb 23, 2026

Problem

Clients like OpenClaw and Cline send v1beta-style thinkingLevel (string: "NONE", "LOW", "MEDIUM", "HIGH") in generationConfig.thinkingConfig. When AGM proxies the request through Google's v1internal API, Google rejects thinkingLevel with 400 INVALID_ARGUMENT because v1internal only accepts numeric thinkingBudget.

The existing is_adaptive check (line ~215) detects thinkingLevel presence to set maxOutputTokens, but the thinkingLevel field itself is never removed or converted — it passes through to Google and causes the 400 error.

Fix

Insert a conversion step in wrap_request() before the existing budget processing logic:

  1. Check if thinkingConfig.thinkingLevel exists (string)
  2. Map it to a numeric thinkingBudget:
    • NONE → 0
    • LOW → 4096
    • MEDIUM → 8192
    • HIGH → 24576
  3. Remove thinkingLevel, insert thinkingBudget
  4. Log the conversion for debugging

This runs early so all downstream logic (budget capping, maxOutputTokens adjustment, adaptive detection) sees the correct numeric budget.

Testing

Tested with OpenClaw sending thinkingLevel: "LOW" to gemini-3.1-pro-high via Gemini native protocol — requests now succeed (200 OK) instead of returning 400.

Files Changed

  • src-tauri/src/proxy/mappers/gemini/wrapper.rs — 23 lines added (conversion block only)

…lity

Clients like OpenClaw and Cline send v1beta-style thinkingLevel (string:
"NONE"/"LOW"/"MEDIUM"/"HIGH") in generationConfig.thinkingConfig. When AGM
proxies through v1internal, Google rejects thinkingLevel with 400
INVALID_ARGUMENT because v1internal only accepts thinkingBudget (numeric).

This fix converts thinkingLevel to the corresponding thinkingBudget value
before any budget processing, then removes the thinkingLevel field. The
conversion runs early in wrap_request so downstream budget capping and
maxOutputTokens logic sees the correct numeric budget.

Mapping: NONE=0, LOW=4096, MEDIUM=8192, HIGH=24576.
lbjlaq added a commit that referenced this pull request Feb 25, 2026
…lity

Manually merged PR #2095 from thebtf:fix/thinking-level-conversion.

Problem:
Clients like OpenClaw and Cline send v1beta-style thinkingLevel (string:
"NONE", "LOW", "MEDIUM", "HIGH") in generationConfig.thinkingConfig.
When AGM proxies through Google's v1internal API, Google rejects thinkingLevel
with 400 INVALID_ARGUMENT because v1internal only accepts numeric thinkingBudget.

Fix:
Insert a conversion step in wrap_request() before existing budget processing:
- NONE  → 0
- LOW   → 4096
- MEDIUM → 8192
- HIGH  → 24576

Tested with OpenClaw sending thinkingLevel: "LOW" to gemini-3.1-pro-high
via Gemini native protocol — requests now succeed (200 OK) instead of 400.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant