Incremental generation
Stream incremental language-model text or other generated content from a server action to a client component.
AI Tools · Function
Creates a server-to-client stream for any serializable value. Control it with update, appendValue, done, and error, then consume the resulting value with the corresponding RSC reading APIs.
The function creates a server-side stream whose serializable value can be returned to a client. Use update to replace the current value, appendValue to append string deltas, done to finalize it, and error to signal a client-side failure.
createStreamableValue(value?: any): StreamableValueWrapper| Name | Type | Description |
|---|---|---|
value | any | Initial serializable value for the stream; it may be omitted. |
An object containing value plus update, appendValue, done, and error methods. The value is a StreamableValue that can be returned from a Server Action.
import { createStreamableValue } from '@ai-sdk/rsc';
export async function generate() {
const stream = createStreamableValue('');
stream.update('Hello');
stream.done();
return stream.value;
}Creates a text stream, updates it once, finalizes it, and returns the value for client consumption.
Stream incremental language-model text or other generated content from a server action to a client component.
Send evolving JSON, arrays, numbers, or other serializable state while server work runs.
Expose completion and failure states alongside a streamed response.
It creates a stream that sends serializable values from the server to the client. The returned value can be consumed with readStreamableValue or useStreamableValue.
Follow-up: What happens if the stream is never finalized? The client remains in a loading state because done must be called.
Pass an initial serializable value, or omit the argument when no initial value is needed. The stream exposes update for replacing the current value and appendValue for adding string deltas.
Follow-up: When is appendValue unsuitable? It cannot be used unless the current stream value is a string.
Call done with no argument to retain the current value, or pass a final value to set the ending state. Calling error marks the stream as failed, and that error is thrown when the client consumes it.
Follow-up: Can a finalized stream be changed? No; finalization prevents later updates and appends.
readStreamableValueuseStreamableValuecreateStreamableUI