Skip to main content
Creates a streamable UI from LLMs in React Server Components.

Parameters

LanguageModelV3
required
The language model to use.
string
A simple text prompt. You can either use prompt or messages but not both.
Array<CoreMessage>
A list of messages. You can either use prompt or messages but not both.
string
A system message that will be part of the prompt.
Record<string, RenderTool>
The tools that the model can call. The model needs to support calling tools.
ToolChoice
The tool choice strategy. Default: 'auto'.
RenderText
Renderer for text content. Receives an object with content, delta, and done properties.
ReactNode
Initial React node to display before any content is generated.
number
Maximum number of tokens to generate.
number
Temperature setting. The value is passed through to the provider.
number
Nucleus sampling. The value is passed through to the provider.
number
Only sample from the top K options for each subsequent token.
number
Presence penalty setting.
number
Frequency penalty setting.
number
The seed (integer) to use for random sampling.
number
default:"2"
Maximum number of retries. Set to 0 to disable retries.
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.
ProviderOptions
Additional provider-specific options.
(event: OnFinishEvent) => void
Callback that is called when the LLM response and the final object validation are finished.

Tool Definition

RenderTool

string
Description of what the tool does.
ZodSchema | Schema
The schema that defines the input shape for the tool.
Renderer
The render function for the tool. Can be:
  • A function that returns a React node
  • A generator function that yields intermediate React nodes
  • An async generator function that yields intermediate React nodes

RenderText

A function that renders text content:

Returns

ReactNode
The React node value that can be returned from a Server Action and rendered on the client.
ReadableStream
The underlying stream from the language model.
LanguageModelV3StreamResult['response']
Response metadata from the language model.
LanguageModelV3StreamResult['request']
Request metadata.

Examples

Basic text rendering

With tools

Streaming tool output

Multiple tools