Skip to content
Source
Sign inSign up
TanStack/ai

chat({ reasoning }) is silently dropped for models added with extendAdapter/createModel (Gemini, OpenAI) #2295

OpenXhale1(GitHub profile, opens in a new tab) opened this issue 1 comment
Xhale1(GitHub profile, opens in a new tab)commented

Disclaimer: I used Opus 5.5 to help report this issue. I ran into it while migrating my company's repo from Vercel AI to Tanstack AI.

TanStack AI version

@tanstack/ai 1.10.1, @tanstack/ai-gemini 1.3.1, @tanstack/ai-openai 1.2.1

Framework/Library version

Node 26, server only

Describe the bug and the steps to reproduce it

chat({ reasoning }) does nothing for a model added with extendAdapter + createModel, even when the model declares createModel(name, { reasoning }). The request goes out with no thinking or reasoning field, and nothing is logged.

Cause: extendAdapter returns the factory unchanged (packages/ai/src/extend-adapter.ts), so the custom model definitions never reach the adapter at runtime. The Gemini text adapter then looks up GEMINI_MODEL_REASONING[options.model] (mapCommonOptionsToGemini), and the OpenAI text adapter looks up OPENAI_MODEL_REASONING[model] (modelReasoning). Both get undefined, so geminiThinkingConfig / the Responses mapping return nothing. The createModel doc comment says only openaiCompatible reads reasoning, which matches what we see.

Two things make this hard to notice:

  • chat({ reasoning: 'high' }) type-checks for these models, even when createModel declares no reasoning at all.
  • Since #1692, thinkingConfig (Gemini) and reasoning (OpenAI) are no longer in the typed modelOptions. The adapters still spread modelOptions into the request, so they work at runtime, but they're a type error (TS2353). So there's no typed way to turn on thinking for a model the adapter doesn't list.

#2119 (gemini-4-argon) and #2224 (ai-claude-code) are the same failure for listed models that lack reasoning data. A warning would have surfaced both.

Steps:

  1. npm i @tanstack/ai@1.10.1 @tanstack/ai-gemini@1.3.1 @tanstack/ai-openai@1.2.1 in an ESM package.
  2. Save repro.mjs below and run node repro.mjs. It makes no network calls: it calls the request-mapping methods chatStream() uses (private in the .d.ts, public at runtime) and prints the field each adapter would send.
// repro.mjs
import { createModel, extendAdapter } from "@tanstack/ai";
import { createGeminiChat } from "@tanstack/ai-gemini";
import { createOpenaiChat } from "@tanstack/ai-openai";

// The request each adapter builds for chat({ reasoning: 'high' }). No network.
const options = (model) => ({
  model,
  messages: [{ role: "user", content: "hi" }],
  tools: [],
  reasoning: { level: "high", summary: true },
});
const levels = { levels: { low: "low", medium: "medium", high: "high" }, budget: false };

const customGemini = extendAdapter(createGeminiChat, [
  createModel("my-gemini-model", { input: ["text"], reasoning: levels }),
]);
const customOpenai = extendAdapter(createOpenaiChat, [
  createModel("my-openai-model", { input: ["text"], reasoning: levels }),
]);

const gemini = (adapter, model) =>
  adapter.mapCommonOptionsToGemini(options(model)).config.thinkingConfig;
const openai = (adapter, model) => adapter.mapOptionsToRequest(options(model)).reasoning;

console.log(
  "gemini-3.8-flash:",
  gemini(createGeminiChat("gemini-3.8-flash", "key"), "gemini-3.8-flash"),
);
console.log("my-gemini-model: ", gemini(customGemini("my-gemini-model", "key"), "my-gemini-model"));
console.log("gpt-5.5:         ", openai(createOpenaiChat("gpt-5.5", "key"), "gpt-5.5"));
console.log("my-openai-model: ", openai(customOpenai("my-openai-model", "key"), "my-openai-model"));

Actual output:

gemini-3.8-flash: { includeThoughts: true, thinkingLevel: 'HIGH' }
my-gemini-model:  undefined
gpt-5.5:          { effort: 'high', summary: 'auto' }
my-openai-model:  undefined

Expected: the custom models get the same fields as the listed ones ({ includeThoughts: true, thinkingLevel: 'HIGH' } and { effort: 'high', summary: 'auto' }), or at least a warning that reasoning was dropped.

The type side, in a .ts file:

import { chat, createModel, extendAdapter } from "@tanstack/ai";
import { createGeminiChat, ThinkingLevel } from "@tanstack/ai-gemini";

const createChat = extendAdapter(createGeminiChat, [createModel("my-gemini-model", ["text"])]);

// Type-checks, but the adapter drops it at runtime.
chat({
  adapter: createChat("my-gemini-model", "key"),
  threadId: "t",
  messages: [],
  reasoning: "high",
});

// Works at runtime, but: TS2353 'thinkingConfig' does not exist in type
// 'GeminiToolConfigOptions & GeminiSafetyOptions & GeminiCommonConfigOptions & ...'
chat({
  adapter: createChat("my-gemini-model", "key"),
  threadId: "t",
  messages: [],
  modelOptions: { thinkingConfig: { thinkingLevel: ThinkingLevel.HIGH } },
});

Suggested fix

  1. Keep the createModel definitions at runtime: have extendAdapter wrap the factory so the adapter knows the custom models' reasoning, and have the lookups fall back to it, e.g. GEMINI_MODEL_REASONING[model] ?? customReasoning[model]. The OpenAI adapter already funnels this through modelReasoning(model), and openaiCompatible already reads def.reasoning, so the pattern exists.
  2. Log a warning when reasoning is requested for a model with no reasoning data, instead of dropping it silently.
  3. Optionally, only allow reasoning in the types for a custom model whose createModel declares it.

Workaround

A middleware that writes the provider field into modelOptions itself (this is our Gemini one):

import type { ChatMiddleware } from "@tanstack/ai";
import { ThinkingLevel } from "@tanstack/ai-gemini";

export function geminiThinking(level: ThinkingLevel): ChatMiddleware {
  return {
    name: "gemini-thinking",
    onConfig: (_context, config) => ({
      modelOptions: { ...config.modelOptions, thinkingConfig: { thinkingLevel: level } },
    }),
  };
}

The self-contained repro.mjs above (no API key or network needed).

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

No

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. tanstack-source added labelsbug

  2. Should extendAdapter support declared custom-model reasoning at runtime, or keep its type-only contract and reject that usage in the types? The migration report in #2295 describes reasoning settings omitted from native Gemini and OpenAI requests. The current guide explicitly promises a type-only helper, so runtime forwarding would be a contract change. PR #2156 added custom reasoning to openaiCompatible, not native factories; the reporter's Gemini middleware is an existing workaround. If runtime support is wanted, the proposed API would reuse createModel(name, { reasoning: { levels, budget } }) with extendAdapter and chat({ reasoning }), without a new public option. Scope would cover explicit declarations on custom native Gemini and OpenAI models, preserving built-in model behavior and other factories. Warnings, generic capability registration, catalog updates, and unrelated provider options would stay out of scope. Verification would cover accepted and rejected types, credential-free request bodies, undeclared models, built-in controls, and the required E2E suite. Docs would update the Extend Adapter guide for custom-model callers and the reasoning sections of the Gemini/OpenAI guides for native-adapter users; affected packages would receive changesets. Implementation would wait for agreement on the contract.

  3. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

Sign in to join this conversation.