Open History to see the last commit
1---
2title: Upgrade to 1.0
3id: migrate-v1
4order: 0
5description: "Move a TanStack AI 0.x app to 1.0 in five steps. Swap each removed API for its replacement on the client, on the server, and in saved data."
6keywords:
7 - tanstack ai
8 - migration
9 - upgrade
10 - 1.0
11 - breaking changes
12 - forwardedProps
13 - createChatHook
14---
15
161.0 removes the APIs that 0.x marked as deprecated. Each replacement already shipped in 0.x. Apply this page, then change the version.
17
18## Upgrade in 5 steps
19
201. Run the [codemod](#run-the-codemod). It does the most common renames for you.
212. Update every `@tanstack/ai*` package to `1.0` at the same time. A 1.0 client needs a 1.0 server. If you use `@tanstack/ai-react-ui`, `@tanstack/ai-solid-ui`, or `@tanstack/ai-vue-ui`, remove it. These packages have no 1.0 release.
223. Run your type checker. Fix each error with the sections [In the browser](#in-the-browser) and [On the server](#on-the-server).
234. If you keep data from 0.x (chats, runs, files), do the steps in [Saved data](#saved-data) before you deploy.
245. Do the [done check](#done).
25
26## Run the codemod
27
28```bash
29npx jscodeshift \
30 --parser=tsx \
31 -t https://raw.githubusercontent.com/TanStack/ai/main/codemods/ag-ui-compliance/transform.ts \
32 "src/**/*.{ts,tsx}"
33```
34
35To see the changes before the codemod writes them, add `--dry --print`.
36
37The codemod does these renames:
38
39| Before | After |
40| --- | --- |
41| `useChat({ body })` | `useChat({ forwardedProps })` |
42| `new ChatClient({ body })` | `new ChatClient({ forwardedProps })` |
43| `client.updateOptions({ body })` | `client.updateOptions({ forwardedProps })` |
44| Svelte `chat.updateBody(x)` | `chat.updateForwardedProps(x)` |
45| `chat({ conversationId: x })` | `chat({ threadId: x })` |
46
47The codemod does not do these changes. Do them by hand:
48
49- Server code that reads `body.data`. See [Read `forwardedProps`, not `data`](#read-forwardedprops-not-data).
50- The value of `threadId` after the rename. The codemod changes the key only. See [`conversationId` is now `threadId`](#conversationid-is-now-threadid).
51- `body` in `createChatHook`, in `useAppChat` overrides, and in Angular `injectChat`.
52
53The codemod changes a file only when the file imports the hook or class from a TanStack AI package. A call through a re-export (a barrel file) does not change.
54
55## In the browser
56
57This section is for code that uses `useChat`, `ChatClient`, a chat UI factory, or any other client package.
58
59### `body` is now `forwardedProps`
60
61The chat-level `body` option is gone from these places:
62
63- `ChatClient` and `updateOptions`.
64- Every chat hook, and Angular `injectChat`.
65- `createChatHook` and `useAppChat` overrides.
66
67Use `forwardedProps`:
68
69```diff
70 useChat({
71 connection: fetchServerSentEvents('/api/chat'),
72- body: { provider: 'openai' },
73+ forwardedProps: { provider: 'openai' },
74 })
75```
76
77On Svelte, `updateBody` is now `updateForwardedProps`.
78
79These options keep the name `body`, because each one is a different option:
80
81- The connection adapter option, for example `fetchServerSentEvents(url, { body })`.
82- The per-call option, `sendMessage(content, { body })`.
83- The generation hooks, for example `useGenerateImage({ body })` and its `updateBody`.
84
85### Interrupts
86
87Read `interrupts`. Resolve each item with its own methods:
88
89```diff
90- const { pendingInterrupts, resumeInterrupts } = useChat(chatOptions)
91+ const { interrupts } = useChat(chatOptions)
92
93- const approval = pendingInterrupts.find((item) => item.kind === 'tool-approval')
94- await resumeInterrupts(resumeItems)
95+ const approval = interrupts.find((item) => item.kind === 'tool-approval')
96+ if (approval?.kind === 'tool-approval') approval.resolveInterrupt(true)
97
98- interrupt.error?.message
99+ interrupt.errors[0]?.message
100```
101
102| Removed | Use instead |
103| --- | --- |
104| `pendingInterrupts` | `interrupts` |
105| `ChatClient.getPendingInterrupts()` | `ChatClient.getInterrupts()` |
106| `resumeInterrupts(items)` | `interrupt.resolveInterrupt(...)`, `interrupt.cancel()`, or `resolveInterrupts(...)`. For raw recovery tools, `resumeInterruptsUnsafe(items)`. |
107| `interrupt.error` | `interrupt.errors[0]` |
108| `addToolApprovalResponse()` (all frameworks and `ChatClient`) | `resolveInterrupt` on the bound `tool-approval` interrupt |
109
110An interrupt from a 0.x server that has no binding now shows as `kind: 'unbound'`. You cannot resume it. The error codes `legacy-unsupported` and `legacy-submit-failed` are gone. For a full approval screen, see [Tool Approval](../interrupts/tool-approval).
111
112### Client tools
113
114A client tool resumes only when the tool on the server and the `.client()` tool in the browser have the same schemas, `outputSchema` included. If the schemas are different, the client does not run the tool. The pause shows as a generic interrupt, and it waits until something resolves it.
115
116To keep the schemas the same, define the tool one time with `toolDefinition()`, and share that definition between the server and the client:
117
118```typescript ignore
119// tools/show-notification.ts: import this file on the server and in the browser
120export const showNotificationDef = toolDefinition({
121 name: 'showNotification',
122 description: 'Show a toast notification in the browser',
123 inputSchema: z.object({ message: z.string() }),
124 outputSchema: z.object({ success: z.boolean() }),
125})
126
127// Browser
128const showNotification = showNotificationDef.client(({ message }) => {
129 toast(message)
130 return { success: true }
131})
132```
133
134See [Client Tools](../tools/client-tools).
135
136### Chat UI components
137
138These ready-made components are gone from `@tanstack/ai-react/ui`, `@tanstack/ai-solid/ui`, `@tanstack/ai-vue/ui`, and `@tanstack/ai-remix/ui`:
139
140- `Chat`, `ChatMessages`, `ChatMessage`, and `ChatInput`.
141- `ToolApproval`.
142- The old `useChatContext` export.
143
144Their prop types are gone too. Build the UI with `createChatHook`. You supply each component, and the factory types them from your chat options:
145
146```diff
147- import { Chat, ChatMessages, ChatInput } from '@tanstack/ai-react-ui'
148+ import { createChatHook } from '@tanstack/ai-react/ui'
149
150+ const { useAppChat } = createChatHook({
151+ options: chatOptions,
152+ components: {
153+ layout: ({ Messages, Input }) => (
154+ <main>
155+ <Messages />
156+ <Input />
157+ </main>
158+ ),
159+ message: ({ message, Parts }) => <article data-role={message.role}><Parts /></article>,
160+ input: ChatForm,
161+ },
162+ partsComponents: { text: ({ part }) => <p>{part.content}</p>, fallback: () => null },
163+ })
164
165- export function ChatScreen() {
166+ export function ChatScreen({ threadId }: { threadId: string }) {
167- return (
168- <Chat connection={connection}>
169- <ChatMessages />
170- <ChatInput />
171- </Chat>
172- )
173+ const chat = useAppChat({ threadId })
174+ return <chat.AppChat />
175 }
176```
177
178`TextPart` and `ThinkingPart` stay. Import them from the same `/ui` subpath.
179
180For a complete, runnable version, start with [A chat box with no tools](../ui/recipes/basic-chat). Then open the guide for your framework: [React](../ui/react), [Solid](../ui/solid), [Vue](../ui/vue), or [Remix](../ui/remix). If you build your own framework adapter, use `createChatUI`. See [Custom adapters](../ui/custom-adapters).
181
182### Pass a `threadId` to every chat and generation hook
183
184`threadId` is now required. The client does not make one for you. This applies to:
185
186- `useChat` and the other chat hooks, and Angular `injectChat`.
187- The hook that `createChatHook` returns. The factory options no longer take `threadId`. Pass it on each call, for example `useAppChat({ threadId })`.
188- `ChatClient`.
189- The generation hooks, for example `useGenerateImage` and `useGeneration`. On Octane, the generation hooks take `threadId` instead of `id`. A generation `fetcher` gets the `threadId` and `runId` in its second argument: `fetcher: (input, { threadId, signal }) => ...`.
190
191```diff
192- useChat({ connection })
193+ useChat({ connection, threadId: chatId })
194```
195
196Use a stable id for each conversation. For example, use the id from your route or your database. Do not make a new random id on each render: a new id starts a new conversation.
197
198The codemod cannot add `threadId`, because it does not know your ids.
199
200If you call a connection adapter yourself, pass a run context with a `threadId` as the fourth argument of `connect()` or `send()`. The types require it, and the call fails without it.
201
202### Other client renames
203
204| Removed | Use instead |
205| --- | --- |
206| `RealtimeAdapter`, `RealtimeConnection` from `@tanstack/ai-client` | Import them from `@tanstack/ai` |
207| `useWebMCPTools` (React, Preact, Solid, Vue, Octane) | `useRegisterWebMCPTools` |
208| `injectWebMCPTools` (Angular) | `injectRegisterWebMCPTools` |
209| `createWebMCPTools` (Svelte, Remix) | `createRegisterWebMCPTools` |
210| Client persistence `getItem` that returns `UIMessage[]` | Return `{ messages }` (see [Saved data](#saved-data)) |
211
212Each WebMCP options type follows its function. For example, `UseWebMCPToolsOptions` is now `UseRegisterWebMCPToolsOptions`.
213
214## On the server
215
216This section is for these parts of your app:
217
218- Your chat endpoint.
219- Middleware and custom adapters.
220- A server that is not TanStack AI, but streams to a TanStack AI client.
221
222### `conversationId` is now `threadId`
223
224```diff
225 const params = await chatParamsFromRequest(request)
226 const stream = chat({
227 adapter: openaiText('gpt-6.1-sol'),
228 messages: params.messages,
229- conversationId: params.forwardedProps.conversationId,
230+ threadId: params.threadId,
231 })
232```
233
234The client sends `threadId` as a top-level field, not in `forwardedProps`. After the codemod, change the value to `params.threadId`. Do not remove the option: `threadId` is now required. See [`chat()` and the generation functions need a `threadId`](#chat-and-the-generation-functions-need-a-threadid).
235
236Middleware reads `ctx.threadId`. `ctx.conversationId` is gone.
237
238### `chat()` and the generation functions need a `threadId`
239
240`threadId` is now required on `chat()`, `summarize()`, and the generation functions, for example `generateImage()`. The server does not make one for you.
241
242```diff
243- chat({ adapter, messages: params.messages })
244+ chat({ adapter, messages: params.messages, threadId: params.threadId })
245```
246
247- In a chat route, use `params.threadId` from `chatParamsFromRequest()`.
248- In a generation route, use `threadId` and `runId` from `generationParamsFromRequest()`. It throws when the body has no `threadId` or `runId`, so a body that holds only the input, with no AG-UI envelope, is rejected. The generation hooks always send the envelope.
249- In a subagent `run` function, `ctx.chat()` and the other `ctx` functions fill `threadId` from the child run. A plain `chat()` call in `run` needs `threadId: ctx.threadId`.
250- `createChatOptions()` does not need a `threadId`. Pass it on the `chat()` call that uses the options.
251
252These also need a `threadId` now:
253
254- `codeModeWithSnippets()` and `selectRelevantSnippets()` from `@tanstack/ai-code-mode-snippets`.
255- `CompactionContext.threadId` and `SummarizeInput.threadId` in `@tanstack/ai-compaction`. This is the conversation id. Give a summary model call its own id, for example `${threadId}:compaction`.
256- `createToolBridgeCore()`, `startHostToolBridge()`, a custom `ToolBridgeProvisioner`, and `executeHostTool()` from `@tanstack/ai-sandbox`. The bridged tools get this `threadId`.
257
258### Read `forwardedProps`, not `data`
259
260The client sends the extra fields only as `forwardedProps`. The `data` copy is gone.
261
262```diff
263 const params = await chatParamsFromRequest(request)
264- const provider = params.forwardedProps.provider ?? body.data?.provider
265+ const provider = params.forwardedProps.provider
266```
267
268`chatParamsFromRequestBody(body).context` is now `aguiContext`.
269
270The generation hooks (for example `useGenerateImage`) do the same. They send the input only in `forwardedProps` of the request body. If a custom generation route reads `body.data`, change it to read `body.forwardedProps`:
271
272```diff
273 const body = await request.json()
274- const { prompt } = body.data
275+ const { prompt } = body.forwardedProps
276```
277
278### Custom servers that stream to a TanStack AI client
279
280If your server does not use `chat()` and `toServerSentEventsResponse()`, make these changes:
281
282- **Stop sending `data: [DONE]`.** End the run with a `RUN_FINISHED` event. The client cannot parse a `[DONE]` line, and it reports an error.
283- **Set `message` on `RUN_ERROR`.** The client reads only the top-level `message` and `code`. It ignores a nested `error.message`.
284- **Send thinking as `REASONING_*` events.** The client does not read `STEP_STARTED` or `STEP_FINISHED` for thinking text.
285- **Send approvals and client tools as interrupts.** End the run with `RUN_FINISHED` and an interrupt outcome. The client does not read the CUSTOM events `approval-requested` and `tool-input-available`. See [Interrupts](../interrupts/overview).
286
287The TanStack AI adapters no longer send `STEP_STARTED` or `STEP_FINISHED` for reasoning. If your middleware or devtools read those events for thinking, read the `REASONING_*` events.
288
289### Video adapters
290
291`getVideo()` is now required, and `getVideoUrl()` is gone from `VideoAdapter` and `BaseVideoAdapter`:
292
293```diff
294 class MyVideoAdapter extends BaseVideoAdapter {
295- async getVideoUrl(jobId: string) {
296+ async getVideo(jobId: string) {
297 return { jobId, url: await this.fetchUrl(jobId) }
298 }
299 }
300```
301
302In app code, call `getVideoJobStatus({ adapter, jobId })`, not `adapter.getVideoUrl(jobId)`. See [Video Generation](../media/video-generation).
303
304### Usage numbers
305
306`TokenUsage.durationSeconds` and `TokenUsage.unitsBilled` are gone. Read `billed`. It holds the quantity and its unit:
307
308```diff
309- const seconds = result.usage?.durationSeconds
310+ const billed = result.usage?.billed
311+ const seconds = billed?.unit === 'seconds' ? billed.quantity : undefined
312```
313
314The OpenTelemetry attributes follow the same change:
315
316- `tanstack.ai.usage.duration_seconds` and `tanstack.ai.usage.units_billed` are gone.
317- Read `tanstack.ai.usage.billed_quantity` and `tanstack.ai.usage.billed_unit`.
318
319See [OpenTelemetry](../advanced/otel).
320
321### `promptTokens` on Anthropic, Bedrock, and Claude Code
322
323In 1.0, `usage.promptTokens` is the full input on every adapter: the uncached tokens, plus the cache reads, plus the cache writes. `totalTokens` uses this value.
324
325Older 0.x releases of these adapters counted only the uncached tokens in `promptTokens`:
326
327- `@tanstack/ai-anthropic` before 0.21.0.
328- `@tanstack/ai-bedrock` (Converse) before 0.5.0.
329- `@tanstack/ai-claude-code` before 0.8.0.
330
331If your code adds the cache counts to `promptTokens`, remove that addition. If you keep it, you count the cache two times:
332
333```diff
334 const details = usage.promptTokensDetails
335- const input = usage.promptTokens + (details?.cachedTokens ?? 0) + (details?.cacheWriteTokens ?? 0)
336+ const input = usage.promptTokens
337```
338
339To get only the uncached tokens, subtract `cachedTokens` and `cacheWriteTokens` from `promptTokens`. See [Token usage](../chat/stream-events#token-usage).
340
341### Renamed types and helpers
342
343| Removed | Use instead |
344| --- | --- |
345| `AGUIEventType`, `StreamChunkType` | The `EventType` enum, or `` `${EventType}` `` for the string union |
346| `UsageTotals`, `ImageUsage` | `TokenUsage` |
347| `OtelSpanKind` | `OtelSpanScope` (from `@tanstack/ai/middlewares/otel`) |
348| `StreamProcessor.startAssistantMessage()` | `StreamProcessor.prepareAssistantMessage()` |
349| `ApprovalRequestedEvent`, `ToolInputAvailableEvent` | The interrupt outcome on `RUN_FINISHED` |
350| `toolName` on `TOOL_CALL_START` chunks | `toolCallName` |
351| `resolveDurableThreadId`, `DurableThreadIdRequiredError` (from `@tanstack/ai-sandbox`) | Nothing. `threadId` is always set, so pass the run record's `threadId` to `chat()` |
352
353`prepareAssistantMessage()` returns nothing. The processor makes the assistant message when the first content arrives.
354
355In `@tanstack/ai-event-client`, `CompactionAppliedEvent` and the `'compaction:applied'` event are now `CompactionStateEvent` and `'compaction:state'`.
356
357### Provider adapters
358
359Each provider tool type alias is gone. Use the `Config` name. For example, `WebSearchTool` is now `WebSearchToolConfig`:
360
361| Package | Removed aliases |
362| --- | --- |
363| `@tanstack/ai-anthropic` | `BashTool`, `CodeExecutionTool`, `ComputerUseTool`, `CustomTool`, `MemoryTool`, `TextEditorTool`, `WebFetchTool`, `WebSearchTool` |
364| `@tanstack/ai-gemini` | `CodeExecutionTool`, `ComputerUseTool`, `FileSearchTool`, `GoogleMapsTool`, `GoogleSearchRetrievalTool`, `GoogleSearchTool`, `UrlContextTool` |
365| `@tanstack/ai-openai`, `@tanstack/openai-base` | `ApplyPatchTool`, `CodeInterpreterTool`, `ComputerUseTool`, `CustomTool`, `FileSearchTool`, `FunctionTool`, `ImageGenerationTool`, `LocalShellTool`, `MCPTool`, `ShellTool`, `WebSearchPreviewTool`, `WebSearchTool` |
366| `@tanstack/ai-openrouter` | `WebSearchTool` |
367
368Other provider changes:
369
370| Provider | Change |
371| --- | --- |
372| Anthropic skills | Move `modelOptions.container.skills` to the code execution tool: `codeExecutionTool(config, { skills })`. |
373| Anthropic media type | Delete `mediaType` from image and document metadata. The adapter reads the type from `source.mimeType`. The types `AnthropicImageMediaType` and `AnthropicDocumentMediaType` are gone. |
374| Gemini image models | Google shut down `gemini-3.1-flash-image-preview`, `gemini-3-pro-image-preview`, and `gemini-2.5-flash-image`. Use `gemini-3.1-flash-image`, `gemini-3-pro-image`, or `gemini-3.1-flash-lite-image`. The type `Gemini25FlashImageSize` is gone. |
375| Grok voice | `grok-voice-think-fast-1.0` is now `grok-voice-think-fast-2.0`. |
376
377## Saved data
378
3791.0 does not read some formats that 0.x saved. Do these steps before you deploy:
380
3811. **Finish or clear the runs in progress.** `@tanstack/ai-sandbox-cloudflare` does not read run-log records in the 0.x layout (`status: 'done' | 'error'` and `createdAt`). Finish or delete the runs in progress, then clear the old `rec:` records. `migrateStoredRunRecord` is gone.
3822. **Resolve or drop the pending interrupts.** `@tanstack/ai-persistence` resumes only bound interrupts. A record saved before interrupt bindings existed does not resume.
3833. **Add `blobKey` to artifact records.** `ArtifactRecord.blobKey` is now required, and a record without it does not load. A 0.x record without `blobKey` used the key `artifacts/<runId>/<artifactId>`. Write that value into those records. A custom store must save `blobKey`. `resolveArtifactBlobKey()` is gone, so read `record.blobKey`.
3844. **Return `{ messages }` from client persistence.** `getItem` must return `{ messages, resume? }`. A bare `UIMessage[]` does not load. Wrap old values in `getItem`:
385
386```diff
387 getItem: (id) => {
388 const saved = JSON.parse(localStorage.getItem(id) ?? 'null')
389- return saved
390+ return Array.isArray(saved) ? { messages: saved } : saved
391 },
392```
393
394Two sandbox renames go with these steps:
395
396- In `@tanstack/ai-sandbox`, `FileEvent` is now `SandboxFileEvent`.
397- `SandboxSnapshotBundle.resolveArtifactBlobKey` is gone, because each record has `blobKey`.
398
399See [Client Persistence](../persistence/client-persistence) and [Keep generated files](../persistence/keep-generated-files).
400
401## Done
402
403You are on 1.0 when these three things are true:
404
4051. Your type checker passes.
4062. A search for the removed names finds nothing:
407
408 ```bash
409 grep -rnE "pendingInterrupts|resumeInterrupts\(|addToolApprovalResponse|conversationId|getVideoUrl|durationSeconds|unitsBilled|body\.data" src
410 ```
411
4123. A chat message streams a reply, and a saved chat loads after a page reload.
413
414Do you come from an early 0.x release, with `openai()` adapters or `providerOptions`? Read the [Migration Guide](./migration) first. For the wire format, read [AG-UI Client Compliance](./ag-ui-compliance). For interrupts in depth, read [Migrate to AG-UI interrupts](../interrupts/migration).