Skip to content

fix(ai): fit OpenRouter reasoning budgets to the output limit - #51189

Merged
rekram1-node merged 1 commit into
v2from
openrouter-budget-fit
Sep 24, 2026
Merged

rekram1-node merged 1 commit into
v2from
openrouter-budget-fit

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Issue for this PR

N/A. Found while testing default output limits for #51021.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

OpenRouter now fits reasoning.max_tokens to half the output limit with ProviderShared.fitThinkingBudget, the same rule the other protocols got in #51157.

OpenRouter forwards reasoning.max_tokens as the upstream thinking budget, but its body builder copied the reasoning option through unchanged. Upstreams such as Alibaba and Anthropic reject a budget that is not below the output limit. OpenRouter's Qwen max variant sends a 131,071 budget, so a 32k compaction summary failed:

max_completion_tokens [32000] must be greater than thinking_budget [131071]

  • Minimum: 1,024, Anthropic's minimum, which also covers Gemini's 512.
  • Passes through unchanged: effort-only reasoning, and requests without an output limit.

How did you verify your code works?

  • Unit test: covers halving, a budget already within half, the 1,024 minimum, no output limit, and effort-only reasoning. The OpenRouter suite passes.
  • Live, with feat(core): fit output limits to the context window #51021 applied, on openrouter/qwen/qwen3.8-flash max:
    • Main steps: max_completion_tokens: 131072, reasoning.max_tokens: 65536.
    • Compaction: max_completion_tokens: 32000, reasoning.max_tokens: 16000. The summary completed, where it was rejected before.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@rekram1-node
rekram1-node merged commit 7f245b0 into v2 Sep 24, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the openrouter-budget-fit branch September 24, 2026 18:42
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