Skip to main content
← Guides

Guide

TanStack AI vs Vercel AI SDK for Streaming React Chat

Updated PkgPulse Team6 min read
0

Compare TanStack AI and Vercel AI SDK for streaming React chat. See how each handles Stop, typed tool results, and switching from OpenAI to Anthropic.

Contents

Choose TanStack AI when your chat already speaks AG-UI or you want to call a TanStack Start server function directly from React. Keep Vercel AI SDK when your route and React components already use its UI Message Stream. Both streamed the same chat, rendered a typed server tool result, and passed Stop to the active provider transport in our local test. The difference is the protocol and message types your app will maintain.

Quick decision matrix

What you needTanStack AIVercel AI SDK
Pair a React hook with a chat routeuseChat with fetchServerSentEvents reads TanStack's AG-UI events.useChat with DefaultChatTransport reads the AI SDK UI Message Stream.
Render a typed server tool resultShare the tool definition with the client and narrow a completed tool-call by name.Infer the UI tool types on UIMessage and render the named part in its output-available state.
Stop after partial text arrivesThe local React UI kept the partial reply. The mock provider fetch observed an abort.The local React UI kept the partial reply. The mock provider fetch observed an abort.
Switch providers after a completed turnSwitch the server adapter. The Anthropic request carried the prior OpenAI tool result.Switch the server model. The Anthropic request carried the prior OpenAI tool result.

The hooks have the same name and both routes use server-sent events. The event payloads and the client request bodies differ. Keep the hook and its matching response format together when changing SDKs. You can change the provider inside either route while preserving that route's contract with React. TanStack AI React API · Vercel AI SDK UI stream protocol

Methodology

We mounted each real React hook against the same small chat view. Send asked “Look up plum.” A synthetic provider stream requested lookupSwatch, a server function that returns a fixed object. The UI had to display the swatch as plum #704264 and the assistant reply as “Plum is #704264.” The controlled Stop case held the response open after the prefix “Plum is” so the test could click the button during a stream.

Fixture dependencyTanStack AIVercel AI SDK
Core@tanstack/ai@1.11.0ai@7.1.0
React client@tanstack/ai-react@1.3.0, @tanstack/ai-client@1.4.0@ai-sdk/react@4.0.195
OpenAI adapter@tanstack/ai-openai@1.2.1@ai-sdk/openai@4.0.129
Anthropic adapter@tanstack/ai-anthropic@1.2.4@ai-sdk/anthropic@4.0.114

Both runs used react@19.3.1, react-dom@19.3.1, and zod@4.6.7. React rendered into jsdom. An in-memory fetch connected the hooks to real route handlers. Another fetch supplied synthetic OpenAI Chat Completions and Anthropic Messages streams to the real provider adapters. The test checked the provider requests and the rendered chat. It used no live credentials or paid inference.

Stream and render the tool result

Use a small tool with a predictable result when testing a chat library. A color lookup makes each failure easy to distinguish. If the swatch never appears, check whether the route registered the tool, returned its result to the model, and exposed a completed part to React. The fixture passed the same Zod input and output schemas to both SDKs and parsed the output before returning it from the server. The React view rendered a swatch only after the completed part passed a schema check.

TanStack AI

The hook calls sendMessage(prompt, { body: { provider } }). At the route, chatParamsFromRequest(request) parses the messages and run IDs. The per-send provider value arrives in forwardedProps. The code below is the tested route excerpt after request parsing and server-side adapter selection. The same controller connects the HTTP request, the chat run and the response stream.

const abortController = new AbortController();
request.signal.addEventListener('abort', () => abortController.abort(request.signal.reason), { once: true });
if (request.signal.aborted) abortController.abort(request.signal.reason);
const stream = chat({
  adapter: adapters[provider], messages, threadId, runId, abortController,
  tools: [tanstackTool],
});

return toServerSentEventsResponse(stream, { abortController });

Define the tool with toolDefinition(), register swatchDefinition.server(lookupSwatch) in the server route, and pass the shared definition in the client's tools array. In React, narrow on type === 'tool-call', the tool name and state === 'complete'. The named part's output is typed from the shared schema. This lets React render the swatch while the server retains the lookup implementation. TanStack AI server tools

Vercel AI SDK

The hook sends sendMessage({ text: prompt }, { body: { provider } }). The request body contains the UI messages and provider choice. In the fixture, validateUIMessages() checks the incoming shape with the tool set. Then convertToModelMessages() prepares the conversation for the model. This tested route excerpt starts after the server validates the input and selects the model.

return streamText({
  model,
  messages: await convertToModelMessages(messages, {
    tools: vercelTools,
    ignoreIncompleteToolCalls: true,
  }),
  tools: vercelTools,
  stopWhen: stepCountIs(2),
  abortSignal: request.signal,
  maxRetries: 0,
}).toUIMessageStreamResponse<SwatchMessage>({ consumeSseStream: consumeStream });

The step limit lets the SDK run the tool and then send its result back for the assistant reply. The client uses UIMessage<unknown, never, InferUITools<typeof vercelTools>> as the chat type. Narrow to tool-lookupSwatch in the output-available state and part.output has the swatch shape. Import the UI message type into React with a type-only import so the chat component can use it independently of the server implementation. Vercel AI SDK chatbot tool usage

Check how far Stop travels

A stopped chat can look the same on screen whether the server noticed the disconnect or kept reading from the provider. To tell those paths apart, the test clicked Stop after the partial reply appeared, checked that Send was available again, and asserted that the signal passed to the active mock fetch was aborted. The partial text stayed visible in both SDKs on both adapters.

Use that same check with the HTTP host you plan to ship. Vercel documents request cancellation as an opt-in for matching functions on its Node.js runtime via supportsCancellation. The fixture exercised signal propagation through the code, with deployment, provider-side termination and billing outside its scope. Treat a client abort as evidence about the client and measure upstream cancellation separately on your deployed route. Vercel Functions request cancellation · Vercel AI SDK stopping streams

Change providers without resetting the chat

The fixture completed an OpenAI turn, changed the provider selector, and sent another turn using the same mounted React component and its existing history. The mocked Anthropic Messages request had to contain the previous OpenAI tool result. The new Anthropic turn called the same tool and rendered the same swatch. The route mapped a short allowlisted provider name to an adapter or model. The selector worked without changing the hook or starting a new chat.

A successful switch on an empty chat would only test model selection. Switch with a completed tool turn in history to check re-encoding, then repeat with the message types your app saves. A plain text exchange and a swatch give you a baseline. Applications that store provider-specific reasoning, file references, or hosted tool results need their own replay cases for that history.

Verdict for your codebase

Keep the chat SDK you already use if it passes the stream, tool-result, and Stop checks on your target deployment. Choose TanStack AI if AG-UI is the interface you plan to share with another client or if its server-function transport matches your TanStack Start route. Choose Vercel AI SDK if you already store its UI messages or want to follow its React chat route and tool examples. For an SDK migration, budget time to review saved messages and the code that renders tool parts, even if both versions of the chat look the same. TanStack server-function transport · Vercel AI SDK React hook

The TanStack AI quick start and the Vercel AI SDK chat reference describe their respective client and route APIs. The decision matrix reports the local fixture described above. If you maintain the older Vercel hooks, see the Vercel AI SDK migration guide for the transition to separate UI and model messages.

For dependency research, open the ai package profile or the AI SDK and LangChain package comparison. If your decision also involves retrieval or agent orchestration, see how Vercel AI SDK, OpenAI Agents SDK, and LangChain divide that work.