useChat-based React and Vue UIs.
toResponse()
Both Session and Conversation provide two methods for streaming to the client:
toUIMessageStream(input)— returns aReadableStream<UIMessageChunk>that maps session events to AI SDK 5 typed chunkstoResponse(input, options)— wraps the stream in an HTTPResponsewith SSE headers, ready to return from any route handler
Next.js Example
app/api/chat/route.ts
Resumable Streams
The directtoResponse(input, { signal: req.signal }) pattern is enough for simple request-bound chat. For resumable chat, the server must decouple the active run from the HTTP response:
POSTstarts or attaches to a server-owned run for the chat id.- Client disconnect removes only that subscriber; it should not abort the run.
GET ${endpoint}/${id}/streamreturns the active stream, or204when no stream is running.- Cancellation should be a separate server-side action.
resume: true and customize the GET endpoint with prepareReconnectToStreamRequest.
Custom Data Parts
The stream emits all standard AI SDK 5 chunk types (text-delta, reasoning-delta, tool-input-available, tool-output-available, start, finish, etc.) plus custom OpenHarness data parts for subagent activity, compaction, retry, and turn lifecycle: