Open History to see the last commit
1---
2title: Devtools
3id: devtools
4order: 3
5description: "See what your TanStack AI app does while it runs. The devtools panel shows live messages, runs, tool call inputs and outputs, memory, and errors."
6keywords:
7 - tanstack ai
8 - devtools
9 - debugging
10 - tool inspection
11 - chat inspector
12 - react devtools
13 - observability
14---
15
16Devtools shows the messages sent to the model, the tool input, and the tool result for a chat run.
17
18The TanStack AI devtools panel shows you this while the app runs. It is a plugin for TanStack Devtools. This takes about 3 minutes.
19
20## 1. Install
21
22<!-- ::start:tabs variant="package-manager" mode="dev-install" -->
23
24react: @tanstack/react-ai-devtools @tanstack/react-devtools
25solid: @tanstack/solid-ai-devtools @tanstack/solid-devtools
26preact: @tanstack/preact-ai-devtools @tanstack/preact-devtools
27svelte: @tanstack/svelte-ai-devtools @tanstack/svelte-devtools
28
29<!-- ::end:tabs -->
30
31## 2. Add the panel
32
33Render `TanStackDevtools` with the AI plugin in your app root. Set `connectToServerBus: true` so the panel also gets events from the server.
34
35React:
36
37```tsx
38import { TanStackDevtools } from '@tanstack/react-devtools'
39import { aiDevtoolsPlugin } from '@tanstack/react-ai-devtools'
40
41const App = () => {
42 return (
43 <>
44 <TanStackDevtools
45 plugins={[aiDevtoolsPlugin()]}
46 eventBusConfig={{
47 connectToServerBus: true,
48 }}
49 />
50 </>
51 )
52}
53```
54
55Svelte:
56
57```svelte
58<script lang="ts">
59import { aiDevtoolsPlugin } from '@tanstack/svelte-ai-devtools'
60import { TanStackDevtools } from '@tanstack/svelte-devtools'
61
62const plugins = [aiDevtoolsPlugin()]
63</script>
64
65<TanStackDevtools
66 {plugins}
67 eventBusConfig={{
68 connectToServerBus: true,
69 }}
70/>
71```
72
73If you already use other devtools plugins, add `aiDevtoolsPlugin()` to the same `plugins` array.
74
75## 3. Start the server bus (without Vite)
76
77`connectToServerBus: true` needs a WebSocket/SSE server on port 4206. With Vite, `@tanstack/devtools-vite` starts it for you. Skip this step.
78
79With Next.js or another bundler, start `ServerEventBus` when the server boots. In Next.js, put this in `instrumentation.ts`:
80
81```ts ignore
82export async function register() {
83 if (
84 process.env['NEXT_RUNTIME'] === 'nodejs' &&
85 process.env.NODE_ENV === 'development'
86 ) {
87 const { ServerEventBus } = await import(
88 '@tanstack/devtools-event-bus/server'
89 )
90 const bus = new ServerEventBus()
91 await bus.start()
92 }
93}
94```
95
96## 4. Open the panel
97
98Start the app, open the devtools, and open the AI panel. Send a chat message. The panel lists your chat hook, and the timeline fills with the run, its events, and any tool calls.
99
100## What you see
101
102- **Hook dashboard:** every active TanStack AI hook on the page. This includes chat, structured output, image, video, audio, speech, transcription, and summarize hooks.
103- **Run timeline:** user turns, linked runs, stream events, client snapshots, and server-only events, by `threadId` and `runId`.
104- **Tool calls:** the input and output of each tool call.
105- **Chat state:** the live messages and the message history.
106- **Errors:** errors and exceptions in AI calls.
107
108Also there when you need it:
109
110- **Tool fixture replay:** build a tool payload from the input schema of a tool, and add the result to the chat. See [Tool Fixtures](#tool-fixtures).
111- **Memory inspector:** for chats with `memoryMiddleware`, see what memory recalled and added each turn. See [Memory Inspector](#memory-inspector).
112
113## How it works
114
115Events come from two places:
116
117- **The client.** The headless client sends the state that the browser can see.
118- **The server.** The server sends details that never reach the client, such as middleware and provider stream events. `devtoolsMiddleware` runs inside every `chat()` call and sends these to the server bus. The bus forwards them to the panel.
119
120Each event has a source descriptor and a stable envelope id. The panel uses them to link related events and to skip duplicates.
121
122## Advanced
123
124### Hook dashboard
125
126The panel listens for active TanStack AI clients and shows them in the left sidebar.
127
128- A hook registers when it is created and sends a snapshot at once.
129- It sends a new snapshot when the panel opens or asks for state. So the hooks show up even if you open the panel after the app rendered.
130
131Each hook entry shows its type, lifecycle, message count, run count, and the latest linked `threadId`. Select a hook to open its full timeline.
132
133Chat hooks use a view by turn. A user message wraps every run and event that happened while the model answered that turn. The details view also shows small client and server state snapshots between runs, so you can see what changed.
134
135### Naming hooks
136
137When a page has more than one AI hook, give each one a label with `devtools.name`. The name changes only the label. Hook type, framework, thread id, and run links still come from the TanStack AI client.
138
139```tsx
140import { fetchServerSentEvents, useChat } from '@tanstack/ai-react'
141
142export function SupportChat() {
143 const chat = useChat({
144 threadId: 'support-chat',
145 connection: fetchServerSentEvents('/api/chat'),
146 devtools: {
147 name: 'Support Chat',
148 },
149 })
150
151 // render your chat UI with `chat.messages`, `chat.sendMessage`, etc.
152}
153```
154
155The same option works for the generation hooks:
156
157```tsx
158import { fetchServerSentEvents, useGenerateImage } from '@tanstack/ai-react'
159
160export function ImageStudio() {
161 const image = useGenerateImage({
162 threadId: 'generation-hooks:useGenerateImage',
163 connection: fetchServerSentEvents('/api/image'),
164 devtools: {
165 name: 'Image Studio',
166 },
167 })
168
169 // render your image generation UI with `image.generate` and `image.result`
170}
171```
172
173### Tool Fixtures
174
175When a `useChat` hook gets tools, the panel lists the tools and their schemas. For inputs that use a Standard Schema, the panel shows a small form, so you can build a tool call payload without writing JSON by hand.
176
177When you apply a fixture, the panel adds the tool call and its result to the real chat messages of that hook. The panel saves fixtures in browser localStorage, under the AI devtools namespace. They are there the next time you open the panel.
178
179### Memory Inspector
180
181When a chat uses [`memoryMiddleware`](../memory/overview.md), the **Memory** tab of the hook shows what the server memory backend did for that conversation. The tab groups the data by scope (session):
182
183- **Operations timeline:** the recall for each turn. It shows the query, how many fragments came back, how many characters went into the system prompt, if memory tools were shown to the model, and how long the recall took.
184- **Stored records and facts:** the current contents of the memory store for the scope. This needs an adapter with the optional `inspect`/`listFacts` methods. The built-in `inMemory()` and `redis()` adapters have them. Adapters without them still show the operations timeline.
185
186Memory runs on the server. Its state gets to the panel over the chat stream, as a `CUSTOM` event that the client sends again, the same way generation results do.
187
188- The snapshot shows memory as it was at the start of each turn. So the writes of a turn show up in the snapshot of the next turn.
189- If you open the panel after a turn, it replays the latest memory state. The tab has data even when you open devtools in the middle of a conversation.