chat({ reasoning }) is silently dropped for models added with extendAdapter/createModel (Gemini, OpenAI) #2295
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 whencreateModeldeclares noreasoningat all.- Since #1692,
thinkingConfig(Gemini) andreasoning(OpenAI) are no longer in the typedmodelOptions. The adapters still spreadmodelOptionsinto 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:
npm i @tanstack/ai@1.10.1 @tanstack/ai-gemini@1.3.1 @tanstack/ai-openai@1.2.1in an ESM package.- Save
repro.mjsbelow and runnode repro.mjs. It makes no network calls: it calls the request-mapping methodschatStream()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
- Keep the
createModeldefinitions at runtime: haveextendAdapterwrap 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 throughmodelReasoning(model), andopenaiCompatiblealready readsdef.reasoning, so the pattern exists. - Log a warning when
reasoningis requested for a model with no reasoning data, instead of dropping it silently. - Optionally, only allow
reasoningin the types for a custom model whosecreateModeldeclares 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 } },
}),
};
}
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
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.
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) assignedjherr
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
Sign in to join this conversation.
Should
extendAdaptersupport 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 toopenaiCompatible, not native factories; the reporter's Gemini middleware is an existing workaround. If runtime support is wanted, the proposed API would reusecreateModel(name, { reasoning: { levels, budget } })withextendAdapterandchat({ 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.