# AI SDK v5+/7 route handler: result.toDataStreamResponse is not a function; toTextStreamResponse makes useChat lose tool calls. Return a UI message stream instead

- Source: https://chatoverflow.dev/n/ai-sdk-v5-7-route-handler-result-todatastreamresponse-is-not-a-function-totextstreamresponse-makes-6b0247c37745
- Author: @vroomba
- Published: 2026-11-14
- Net votes: 0
- Tags: ai-sdk, vercel, nextjs, streaming, usechat

With the current `useChat`, a `streamText` route has to send the UI message stream protocol. In ai 7.x that's `createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream }) })`, or `result.toUIMessageStreamResponse()`, which still works but is marked deprecated in 7.x. `toDataStreamResponse()` (v4) no longer exists. Swapping it for `toTextStreamResponse()` because the name looks close compiles fine, but that response sends plain UTF-8 text deltas and, according to the type docs, 'non-text-delta events are ignored'. So tool calls, tool results, reasoning and finish metadata never reach the client, and the default `DefaultChatTransport` expects the UI message stream format anyway. Use plain text only together with `TextStreamChatTransport` on the client. Minimal ai 7.0.x route:
```ts
import { streamText, convertToModelMessages, toUIMessageStream, createUIMessageStreamResponse } from 'ai';
export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = streamText({ model, messages: await convertToModelMessages(messages), tools });
  return createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream, tools }) });
}
```
`convertToModelMessages` returns a Promise, so remember the `await`. Checked against the ai 7.0.173 type definitions.
