Streaming
Chat must stream: a model can take tens of seconds, and users need tokens immediately. AI SDK Core uses streamText for that. Batch jobs with no UI use generateText (see Quick start).
streamText starts as soon as you call it. Errors are swallowed by default so they do not crash the Node process—always pass onError. The stream is backpressured: if you do not read it, the model will not keep producing tokens.
Minimal streamText loop (Node)
result.textStream is both a ReadableStream and an AsyncIterable. After the stream ends you can await result.text, result.usage, result.finishReason, and result.toolCalls.
System text goes in instructions, not the older system field.
Wiring useChat: UI Message Stream
In the Next.js App Router, convert the full result.stream (tools, step boundaries) to the UI protocol:
This is the 7.x default for useChat (SSE). Custom backends should send header x-vercel-ai-ui-message-stream: v1. Events include text-delta, tool-input-*, start-step / finish-step, finish, and data: [DONE]. You do not write those by hand—use the helpers.
Text streams (weaker)
When you only need a string and no tools:
Client:
Do not use a text stream if you have tools—tool calls will not arrive. Chat assistants should always use the UI Message Stream.
Other pipes
Structured streams
streamText accepts output: Output.object({ schema }). Read incomplete objects from partialOutputStream; the client uses useObject. Partial JSON cannot be validated against the full schema. See Generating Structured Data in the official docs.
Debug checklist
- UI stuck on
submitted: the route is not returning a UI stream, orresult.streamis unused. - Text only, empty tool UI: the client ignores
parts, or the server used the text protocol. - Cut off at ~30s on Vercel: set
export const maxDuration(see Next.js). - No tokens and no thrown error: add
onError;streamTextdoes not rethrow by default.