Skip to content

fix(ai-openrouter): add GPT-6.1 Terra reasoning levels - #2343

Closed
adamkasper wants to merge 1 commit into
TanStack:mainfrom
adamkasper:fix/openrouter-gpt-6-1-terra-reasoning
Closed

adamkasper wants to merge 1 commit into
TanStack:mainfrom
adamkasper:fix/openrouter-gpt-6-1-terra-reasoning

Conversation

@adamkasper

@adamkasper adamkasper commented Dec 5, 2026 •

Copy link
Copy Markdown

chat({ reasoning }) has no effect for GPT-6.1 Terra on OpenRouter. The adapter sends no reasoning field, and the types reject every level. This PR adds the levels that OpenRouter lists for openai/gpt-6.1-terra, openai/gpt-6.1-terra-pro, and their :batch ids.

🎯 Changes

  • model-meta.ts: Terra and Terra batch get off to max (EFFORT_NONE_LOW_TO_MAX). Terra Pro and Terra Pro batch get low to max (EFFORT_LOW_TO_MAX). All four ids are now in OPENROUTER_REASONING.
  • Type test: Terra accepts off. Terra Pro accepts max and rejects off.
  • E2E: a new terra case in openrouter-reasoning-wire.spec.ts checks that the request has reasoning: { effort: 'low' }.
  • Patch changeset for @tanstack/ai-openrouter.
  • No docs change. The OpenRouter adapter page already says that the types know the levels of each model.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Root cause

Issue. For the four Terra ids, chat({ reasoning }) is a type error. At runtime, the adapter sends no reasoning field, so OpenRouter uses its default effort (medium).

Cause. The four ids have no entry in OPENROUTER_MODEL_REASONING. resolveReasoning() in adapters/text.ts gets undefined and returns no effort. The daily sync does not add the entry, because scripts/convert-openrouter-models.ts only copies the shapes that model-meta.ts already has.

Fix. Add the four entries with the efforts from the OpenRouter catalog. The types and the request path read the same map, so both now work.

Possible alternatives

Test plan

Commands run

  • NX_BASE=origin/main pnpm test:pr: passed.
  • pnpm --filter @tanstack/ai-e2e test:e2e --workers=1: 868 passed, 4 skipped.
  • pnpm --filter @tanstack/ai-e2e test:e2e tests/openrouter-reasoning-wire.spec.ts: on main with only the test changes of this PR, the terra case fails (Expected: {"effort": "low"}, Received: undefined). On this branch, all three cases pass.
  • A repro script on clean main (a7501eb0a) and on this branch. The script calls chat({ reasoning }) with every level that the catalog lists, and records the reasoning.effort of the request.

main:

openai/gpt-6.1-terra             {"max":"(missing)","xhigh":"(missing)","high":"(missing)","medium":"(missing)","low":"(missing)","off":"(missing)"}
openai/gpt-6.1-terra-pro         {"max":"(missing)","xhigh":"(missing)","high":"(missing)","medium":"(missing)","low":"(missing)"}
openai/gpt-6.1-terra-pro:batch   {"max":"(missing)","xhigh":"(missing)","high":"(missing)","medium":"(missing)","low":"(missing)"}
openai/gpt-6.1-terra:batch       {"max":"(missing)","xhigh":"(missing)","high":"(missing)","medium":"(missing)","low":"(missing)","off":"(missing)"}
FAIL: 22 levels dropped

This branch:

openai/gpt-6.1-terra             {"max":"max","xhigh":"xhigh","high":"high","medium":"medium","low":"low","off":"none"}
openai/gpt-6.1-terra-pro         {"max":"max","xhigh":"xhigh","high":"high","medium":"medium","low":"low"}
openai/gpt-6.1-terra-pro:batch   {"max":"max","xhigh":"xhigh","high":"high","medium":"medium","low":"low"}
openai/gpt-6.1-terra:batch       {"max":"max","xhigh":"xhigh","high":"high","medium":"medium","low":"low","off":"none"}
PASS: all levels sent
Repro script (node repro.mjs <checkout>, after pnpm build)
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { pathToFileURL } from 'node:url'

const dir = resolve(process.argv[2])
const pkg = (name) =>
  import(pathToFileURL(`${dir}/packages/${name}/dist/esm/index.js`).href)
const { chat } = await pkg('ai')
const { createOpenRouterText } = await pkg('ai-openrouter')
const catalog = JSON.parse(
  readFileSync(`${dir}/scripts/openrouter.models.json`, 'utf8'),
)

let dropped = 0
for (const row of catalog.filter((r) => r.id.startsWith('openai/gpt-6.1-terra'))) {
  const sent = {}
  for (const effort of row.reasoning.supported_efforts) {
    const level = effort === 'none' ? 'off' : effort
    let body
    for await (const _ of chat({
      adapter: createOpenRouterText(row.id, 'k'),
      threadId: 't',
      messages: [{ role: 'user', content: 'x' }],
      reasoning: level,
      wrapFetch: () => async (input, init) => {
        body = await new Request(input, init).json()
        return new Response('data: [DONE]\n\n', {
          headers: { 'content-type': 'text/event-stream' },
        })
      },
    })) {
    }
    sent[level] = body.reasoning?.effort ?? '(missing)'
    if (body.reasoning?.effort !== effort) dropped++
  }
  console.log(row.id.padEnd(32), JSON.stringify(sent))
}
console.log(dropped ? `FAIL: ${dropped} levels dropped` : 'PASS: all levels sent')
process.exit(dropped ? 1 : 0)

Manual test

  1. On main, run pnpm build, then run the script above. Every level shows (missing).
  2. On this branch, run pnpm build, then run the script again. Every level is sent.

How this PR makes testing easy: the type test and the E2E terra case are on the branch. CI runs both.

Risk / rollback

Low risk. Only the four Terra ids change. A call without reasoning sends the same request as before. To undo, revert this PR.

Public API change

Before

chat({
  adapter: openRouterText('openai/gpt-6.1-terra'),
  threadId,
  messages,
  reasoning: 'low', // type error; the request has no `reasoning` field
})

After

chat({
  adapter: openRouterText('openai/gpt-6.1-terra'),
  threadId,
  messages,
  reasoning: 'low', // the request has `reasoning: { effort: 'low' }`
})

@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@changeset-bot

changeset-bot Bot commented Dec 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 62f081d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/ai-openrouter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@adamkasper

Copy link
Copy Markdown
Author

Closed in favor of #2344. #2344 fixes the converter, so the next model sync adds the Terra levels together with the other 27 missing shapes.

@adamkasper adamkasper closed this Dec 5, 2026
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