streamText instead.
Parameters
LanguageModel
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.
ToolSet
Tools that are accessible to and can be called by the model. The model needs to support calling tools.
ToolChoice
The tool choice strategy. Default:
'auto'.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.
Array<string>
Stop sequences. If set, the model will stop generating text when one of the stop sequences is generated.
number
The seed (integer) to use for random sampling.
If set and supported by the model, calls will generate deterministic results.
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.
number
An optional timeout in milliseconds. The call will be aborted if it takes longer than the specified timeout.
Record<string, string>
Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
StopCondition | Array<StopCondition>
default:"stepCountIs(1)"
Condition for stopping the generation when there are tool results in the last step.
When the condition is an array, any of the conditions can be met to stop the generation.
Output
Optional specification for parsing structured outputs from the LLM response.
Array<keyof TOOLS>
Limits the tools that are available for the model to call without changing the tool call and result types in the result.
PrepareStepFunction
Optional function that you can use to provide different settings for a step.
ToolCallRepairFunction
A function that attempts to repair a tool call that failed to parse.
DownloadFunction
Custom download function to use for URLs.
By default, files are downloaded if the model does not support the URL for the given media type.
unknown
Context that is passed into tool execution.
TelemetrySettings
Optional telemetry configuration (experimental).
ProviderOptions
Additional provider-specific options. They are passed through to the provider from the AI SDK
and enable provider-specific functionality that can be fully encapsulated in the provider.
(event: OnStartEvent) => void
Callback invoked when generation begins, before any LLM calls.
(event: OnStepStartEvent) => void
Callback invoked when each step begins, before the provider is called.
(event: OnToolCallStartEvent) => void
Callback invoked before each tool execution begins.
(event: OnToolCallFinishEvent) => void
Callback invoked after each tool execution completes.
(event: OnStepFinishEvent) => void
Callback that is called when each step (LLM call) is finished, including intermediate steps.
(event: OnFinishEvent) => void
Callback that is called when all steps are finished and the response is complete.
Returns
string
The generated text.
Array<ContentPart>
The content parts from the final step.
Array<ToolCall>
The tool calls from the final step.
Array<ToolResult>
The tool results from the final step.
FinishReason
The reason why the generation finished.
LanguageModelUsage
The token usage of the final step.
LanguageModelUsage
The total token usage across all steps.
Array<CallWarning>
Warnings from the model provider (e.g., unsupported settings).
Array<StepResult>
Details for all steps.
LanguageModelResponseMetadata
Response metadata from the final step.
OUTPUT
The parsed output (only when using the
output parameter).