readUIMessageStream
Transforms a stream of UIMessageChunks into an AsyncIterableStream of UIMessages.
UI message streams are useful outside of Chat use cases, e.g. for terminal UIs, custom stream consumption on the client, or RSC (React Server Components).
Import
import { readUIMessageStream } from 'ai';API Signature
Parameters
message?:
UIMessage
stream:
ReadableStream<UIMessageChunk>
onError?:
(error: unknown) => void
terminateOnError?:
boolean
Returns
An AsyncIterableStream of UIMessages. Each stream part represents a different state of the same message as it is being completed.
For comprehensive examples and use cases, see Reading UI Message Streams.