Rendering Streamed Chat
Updated 5 hours ago • May 22, 2026
useChat(...) separates completed history from the current in-flight assistant response.
- Render
messagesfor finalized chat history. - Render
streamContentPiecesfor the active assistant response. - Expect text, structured data, interrupts, and errors to appear before finalization.
- When the stream finishes,
useChat(...)builds and appends the final assistant message.
Basic Pattern
Render Piece Types
Handle each piece type explicitly.
Interrupt Controls
For interrupt pieces, call chat.respondToInterrupt(piece, response) with the same piece you received. This preserves the resumeToken and requestId.
If your workflow emits multiple interrupt types, route custom controls with piece.schemaId.
The piece also preserves schemaVersion, interruptId, and public meta from the server interrupt request.
Abort and Errors
Show an abort control while a stream is active.
Common Mistakes
- Rendering live assistant text from both
streamContentPiecesand the latestmessagesentry. - Returning
ui.messagewith the same text already streamed byuseReason({ emit: true }). - Treating
messagesas token-by-token state. - Ignoring structured pieces and wondering why cards or previews do not update.
- Rendering interrupt UI without preserving the original piece's
resumeTokenandrequestId. - Building a custom transport but not forwarding
AbortSignal.