new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

AI SDK · Core · all subjects

streamtext options

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

streamText abortSignal parameter

The streamText function accepts an abortSignal argument that you can use to cancel a stream. This is used to cancel a stream from the server side to the LLM API, such as by forwarding the abortSignal from the request.

streamText onAbort callback

The streamText function accepts an onAbort callback that is called when a stream is aborted via AbortSignal. The onAbort callback receives a parameter object with a steps property containing an array of all completed steps before the abort occurred. Unlike onEnd which is called on normal completion, onAbort is specifically for aborted streams.

streamText parameters for chat completions

streamText accepts the following parameters: model (required, string like 'openai/gpt-5.4'), messages (required, array of chat messages with role and content), instructions (optional, string for system-level guidance).

streamRetries option for retrying after streaming starts

The streamRetries option on streamText retries failures that occur after response streaming has begun. It accepts a number indicating the number of retries to attempt.

Stream retries behavior and context preservation

Stream retries rerun only the failed model step with the same accumulated conversation and generation context. Earlier completed steps including tool calls and tool results are not replayed. Tool input, tool calls, approval requests, tool callbacks, and client-side tool execution from a failed attempt are discarded and only exposed or executed after an attempt reaches a successful model-call finish.

onError callback for dynamic retry decisions

The onError callback can be used to dynamically decide whether to retry a stream. It receives an error parameter and can return { retry: true } to request recovery. When streamRetries is set to 0, automatic retries are disabled and recovery is callback-directed only.

Callback-directed recovery retry limits

Callback-directed recovery is limited to one retry per logical step. When automatic retries are configured, onError can request one additional retry after the automatic retry budget is exhausted, bounding the total number of recovery calls for a step to streamRetries + 1.

onError callback behavior when streamRetries is omitted

When streamRetries is omitted, all stream retry behavior is disabled and an existing logging-only onError callback retains incremental tool streaming. An onError return value other than { retry: true } keeps its previous behavior and does not request recovery.

Stream retry callbacks and step tracking

A retry remains part of the same logical step. onStepStart runs once for that step. onLanguageModelCallStart runs for each provider call attempt, while onLanguageModelCallEnd runs only for attempts that reach a model-call finish.

onAbort callback for stream cleanup

The onAbort callback is called when a stream is aborted via AbortSignal, but onEnd is not called. This allows cleanup operations like updating stored messages in the UI.

onAbort callback parameters

The onAbort callback receives an object with a steps property containing an array of all completed steps before the abort.

Give your agent this brain