Skip to content

fix(transform): stream reasoning correctly on the OpenRouter managed path#111

Merged
Aayam Bansal (aayambansal) merged 1 commit into
mainfrom
fix/openrouter-reasoning-stream
Jul 6, 2026
Merged

fix(transform): stream reasoning correctly on the OpenRouter managed path#111
Aayam Bansal (aayambansal) merged 1 commit into
mainfrom
fix/openrouter-reasoning-stream

Conversation

@aayambansal

Copy link
Copy Markdown
Member

Follow-up to the managed⇒OpenRouter routing PR: once wallet inference goes through OpenRouter, its reasoning has to actually stream. OpenRouter exposes reasoning via its unified reasoning / reasoning_details fields, but only when a reasoning object is requested. Three gaps left managed reasoning blank:

  1. options() only requested reasoning for gemini-3. Every other reasoning-capable OpenRouter model (Claude, GPT, DeepSeek, …) got usage.include but no reasoning object → the upstream reasoned silently and OR dropped the trace. Now request reasoning:{effort} for every reasoning-capable OR model (medium; gemini-3 high). A selected effort variant still overrides via mergeDeep in llm.ts.
  2. OR-routed gpt-5 fell into the OpenAI-Responses block and got reasoningEffort / reasoningSummary / include: reasoning.encrypted_content — keys OR ignores — so it requested no reasoning in OR's shape. Exclude the OR npm from that block.
  3. smallOptions() OpenRouter branch was dead code: a small OR gpt-5-nano matched the gpt-5 check first and returned the OpenAI reasoningEffort: "minimal" key (ignored by OR → reasoning still ran and billed on title/summary/compaction). Check OpenRouter first and disable reasoning via OR's unified reasoning:{enabled:false}. (This was a real bug the plan's original edit missed — the new test caught it.)

Direct OpenAI (BYOK + the openai-via-proxy edge) is untouched.

Tests

test/provider/transform-reasoning.test.ts: OR reasoning requested for Claude/GPT/gemini-3; OR gpt-5 uses reasoning.effort not the OpenAI keys; non-reasoning OR models get no reasoning object; direct-OpenAI paths keep their existing keys; small OR disables reasoning. All 69 existing transform tests still pass.

…path

Now that managed wallet inference routes through OpenRouter, its reasoning
must actually stream. OpenRouter emits reasoning via its unified
`reasoning`/`reasoning_details` fields, but only when a `reasoning` object
is requested. Three gaps left managed reasoning blank:

- options() only set `reasoning:{effort}` for gemini-3. Request it for
  every reasoning-capable OpenRouter model (medium effort; gemini-3 high),
  so Claude/GPT/etc routed through OR stream their traces. A selected
  effort variant still overrides via mergeDeep in llm.ts.
- An OR-routed gpt-5 fell into the OpenAI-Responses block and got
  reasoningEffort/reasoningSummary/include — keys OR ignores — so it
  requested no reasoning in OR's shape and streamed an empty trace.
  Exclude the OR npm from that block.
- smallOptions() returned the OpenAI `reasoningEffort` key for OR gpt-5
  small calls (the gpt-5 check ran before the openrouter branch, which was
  therefore dead code). Check OpenRouter first and disable reasoning via
  OR's unified shape so title/summary/compaction don't reason or bill.

Direct OpenAI (BYOK and the openai-via-proxy edge) is unchanged.
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openscience Ready Ready Preview, Comment Jul 6, 2026 3:52pm

Request Review

@aayambansal Aayam Bansal (aayambansal) merged commit b91a212 into main Jul 6, 2026
12 checks passed
@aayambansal Aayam Bansal (aayambansal) deleted the fix/openrouter-reasoning-stream branch July 6, 2026 15:55
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