File: stream-ui.md | Updated: 11/15/2025
Menu
v5 (Latest)
AI SDK 5.x
Model Context Protocol (MCP) Tools
Copy markdown
==============================================================================
AI SDK RSC is currently experimental. We recommend using AI SDK UI for production. For guidance on migrating from RSC to UI, see our migration guide .
A helper function to create a streamable UI from LLM providers. This function is similar to AI SDK Core APIs and supports the same model interfaces.
To see streamUI in action, check out these examples
.
import { streamUI } from "@ai-sdk/rsc"
LanguageModel
The language model to use. Example: openai("gpt-4.1")
ReactNode
The initial UI to render.
string
The system prompt to use that specifies the behavior of the model.
string
The input prompt to generate the text from.
Array<CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage> | Array<UIMessage>
A list of messages that represent a conversation. Automatically converts UI messages from the useChat hook.
CoreSystemMessage
'system'
The role for the system message.
string
The content of the message.
CoreUserMessage
'user'
The role for the user message.
string | Array<TextPart | ImagePart | FilePart>
The content of the message.
TextPart
'text'
The type of the message part.
string
The text content of the message part.
ImagePart
'image'
The type of the message part.
string | Uint8Array | Buffer | ArrayBuffer | URL
The image content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.
string
The IANA media type of the image. Optional.
FilePart
'file'
The type of the message part.
string | Uint8Array | Buffer | ArrayBuffer | URL
The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.
string
The IANA media type of the file.
CoreAssistantMessage
'assistant'
The role for the assistant message.
string | Array<TextPart | ToolCallPart>
The content of the message.
TextPart
'text'
The type of the message part.
string
The text content of the message part.
ToolCallPart
'tool-call'
The type of the message part.
string
The id of the tool call.
string
The name of the tool, which typically would be the name of the function.
object based on zod schema
Parameters generated by the model to be used by the tool.
CoreToolMessage
'tool'
The role for the assistant message.
Array<ToolResultPart>
The content of the message.
ToolResultPart
'tool-result'
The type of the message part.
string
The id of the tool call the result corresponds to.
string
The name of the tool the result corresponds to.
unknown
The result returned by the tool after execution.
boolean
Whether the result is an error or an error message.
number
Maximum number of tokens to generate.
number
Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.
number
Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.
number
Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.
number
Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.
number
Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.
string[]
Sequences that will stop the generation of the text. If the model generates any of these sequences, it will stop generating further text.
number
The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.
number
Maximum number of retries. Set to 0 to disable retries. Default: 2.
AbortSignal
An optional abort signal that can be used to cancel the call.
Record<string, string>
Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
ToolSet
Tools that are accessible to and can be called by the model.
Tool
string
Information about the purpose of the tool including details on how and when it can be used by the model.
zod schema
The typed schema that describes the parameters of the tool that can also be used to validation and error handling.
(async (parameters) => ReactNode) | AsyncGenerator<ReactNode, ReactNode, void>
A function or a generator function that is called with the arguments from the tool call and yields React nodes as the UI.
"auto" | "none" | "required" | { "type": "tool", "toolName": string }
The tool choice setting. It specifies how tools are selected for execution. The default is "auto". "none" disables tool execution. "required" requires tools to be executed. { "type": "tool", "toolName": string } specifies a specific tool to execute.
(Text) => ReactNode
Callback to handle the generated tokens from the model.
Text
string
The full content of the completion.
string
The delta.
boolean
Is it done?
Record<string,Record<string,JSONValue>> | undefined
Provider-specific options. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.
(result: OnFinishResult) => void
Callback that is called when the LLM response and all request tool executions (for tools that have a `generate` function) are finished.
OnFinishResult
TokenUsage
The token usage of the generated text.
TokenUsage
number
The total number of tokens in the prompt.
number
The total number of tokens in the completion.
number
The total number of tokens generated.
ReactNode
The final ui node that was generated.
Warning[] | undefined
Warnings from the model provider (e.g. unsupported settings).
Response
Optional response data.
Response
Record<string, string>
Response headers.
ReactNode
The user interface based on the stream output.
Response
Optional response data.
Response
Record<string, string>
Response headers.
Warning[] | undefined
Warnings from the model provider (e.g. unsupported settings).
AsyncIterable<StreamPart> & ReadableStream<StreamPart>
A stream with all events, including text deltas, tool calls, tool results, and errors. You can use it as either an AsyncIterable or a ReadableStream. When an error occurs, the stream will throw the error.
StreamPart
'text-delta'
The type to identify the object as text delta.
string
The text delta.
StreamPart
'tool-call'
The type to identify the object as tool call.
string
The id of the tool call.
string
The name of the tool, which typically would be the name of the function.
object based on zod schema
Parameters generated by the model to be used by the tool.
StreamPart
'error'
The type to identify the object as error.
Error
Describes the error that may have occurred during execution.
StreamPart
'finish'
The type to identify the object as finish.
'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown'
The reason the model finished generating the text.
TokenUsage
The token usage of the generated text.
TokenUsage
number
The total number of tokens in the prompt.
number
The total number of tokens in the completion.
number
The total number of tokens generated.
Learn to render a React component as a function call using a language model in Next.js Learn to persist and restore states UI/AI states in Next.js Learn to route React components using a language model in Next.js Learn to stream component updates to the client in Next.js
On this page
Deploy and Scale AI Apps with Vercel.
Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.
Trusted by industry leaders: