Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

reasoning-option.md

130 lines4.6 KB

1---
2title: Moving reasoning into chat()
3description: "Move provider reasoning and thinking fields out of modelOptions and into the reasoning option on chat(), adapter by adapter."
4keywords:
5 - tanstack ai
6 - migration
7 - reasoning
8 - thinking
9 - modelOptions
10---
11​
12Move `reasoning`, `thinking`, and `thinkingConfig` out of `modelOptions`. Pass `reasoning` to `chat()` as a level, or as `{ level, summary, budgetTokens }`.
13​
14## Upgrade
15​
161. Delete the reasoning field from `modelOptions`.
172. Set `reasoning` on `chat()`. Find the old field of your adapter in the [table below](#adapter-by-adapter).
183. If you set a token budget, move it to `budgetTokens`. See [Budgets](#budgets).
194. Run your type checker.
20​
21There is no codemod for this change.
22​
23```typescript ignore
24// Before
25chat({
26 adapter: openaiText("gpt-6.1-sol"),
27 messages,
28 modelOptions: { reasoning: { effort: "high", summary: "auto" } },
29});
30```
31​
32```typescript
33import { chat } from "@tanstack/ai";
34import { openaiText } from "@tanstack/ai-openai";
35​
36const messages = [{ role: "user" as const, content: "Hello" }];
37​
38// After
39chat({
40 adapter: openaiText("gpt-6.1-sol"),
41 messages,
42 threadId: "thread-1",
43 reasoning: "high",
44});
45```
46​
47The thinking text streams by default. To hide it, pass `reasoning: { level: "high", summary: false }`.
48​
49## Adapter by adapter
50​
51| Adapter | Old `modelOptions` field | Now |
52| --- | --- | --- |
53| `openaiText`, `openaiChatCompletions`, `azureOpenaiText` | `reasoning: { effort, summary }` | `reasoning: "high"` |
54| `anthropicText` | `thinking`, `effort`, `output_config.effort` | `reasoning: "high"`, or `{ level, budgetTokens }` on budget models |
55| `geminiText` | `thinkingConfig` | `reasoning: "high"`, or `{ level, budgetTokens }` on Gemini 2.5 |
56| `geminiTextInteractions` | `generation_config.thinking_level`, `thinking_summaries` | `reasoning: "high"` |
57| `grokText`, `openRouterText` | `reasoning: { effort }` | `reasoning: "high"` |
58| `vercelGatewayText`, `lovableText` | `reasoning`, `include_reasoning` | `reasoning: "high"` |
59| `bedrockText` | `reasoning_effort` (chat), `reasoning` (Responses) | `reasoning: "high"` |
60| `groqText`, `llmGatewayText`, `cloudflareText` | `reasoning_effort` | `reasoning: "high"` |
61| `byteplusText` | `thinking`, `reasoning_effort` | `reasoning: "high"`, or `"off"` |
62| `ollamaText` | `think` | `reasoning: "high"`, or `"off"` |
63| `codexText` | `modelReasoningEffort` | `reasoning: "high"` |
64​
65`"high"` is an example. Use any level that your model has. The types show the levels of your model.
66​
67## Budgets
68​
69An Anthropic or Gemini 2.5 budget moves to `budgetTokens`:
70​
71```typescript ignore
72// Before
73modelOptions: { thinking: { type: "enabled", budget_tokens: 8000 } }
74```
75​
76```typescript
77import { chat } from "@tanstack/ai";
78import { anthropicText } from "@tanstack/ai-anthropic";
79​
80const messages = [{ role: "user" as const, content: "Hello" }];
81​
82// After
83chat({
84 adapter: anthropicText("claude-haiku-4-5"),
85 messages,
86 threadId: "thread-1",
87 reasoning: { level: "high", budgetTokens: 8000 },
88});
89```
90​
91The adapter raises `max_tokens` when it is below the budget.
92​
93## Azure
94​
95`azureOpenaiText` and `createAzureOpenaiText` read the levels of the OpenAI model name that you pass, not of your deployment name:
96​
97```typescript
98import { chat } from "@tanstack/ai";
99import { createAzureOpenaiText } from "@tanstack/ai-openai";
100​
101const messages = [{ role: "user" as const, content: "Hello" }];
102​
103chat({
104 adapter: createAzureOpenaiText("gpt-6.1-sol", "azure-key", {
105 resourceName: "my-resource",
106 deploymentName: "prod-chat",
107 }),
108 messages,
109 threadId: "thread-1",
110 reasoning: "high",
111});
112```
113​
114If you pass only a deployment name as the model, the adapter has no levels for it, and `reasoning` is a type error. Pass the OpenAI model name, and set `deploymentName`.
115​
116## Codex
117​
118`modelReasoningEffort` stays on the `codexText` config. It is the default for a call without `reasoning`.
119​
120## Removed types
121​
122- `@tanstack/ai-openai`: `OpenAIReasoningOptions`, `OpenAIReasoningOptionsWithConcise`.
123- `@tanstack/ai-anthropic`: `AnthropicThinkingOptions`, `AnthropicAdaptiveThinkingOptions`, `AnthropicAdaptiveOnlyThinkingOptions`, `AnthropicAdaptiveOrDisabledThinkingOptions`, `AnthropicEffortOptions`, `AnthropicOutputConfigOptions`.
124- `@tanstack/ai-gemini`: `GeminiThinkingOptions`.
125- `@tanstack/ai-grok`: `GrokReasoning`, `GrokReasoningEffort`, `GrokBuildProviderOptions`.
126- `@tanstack/ai-openrouter`: `ReasoningOptions`. `@tanstack/ai-byteplus`: `BytePlusThinkingOption`, `BytePlusReasoningEffort`.
127​
128## Done
129​
130Your type checker passes, and no `modelOptions` has a reasoning field. One `reasoning` option now sets reasoning on every provider. For levels, budgets, and middleware, see [Reasoning](../chat/reasoning).