Recover from transient startup failures
Transient provider or network failures occur before a model call starts.
AI Tools · Const
maxRetries controls how many times the AI SDK retries failures while starting a model call. It defaults to 2 and can be set to 0 to disable retries.
Retries are configured through the request option maxRetries, which limits retries for failures encountered while starting a model call. Set it to zero to disable them; stream recovery after streaming begins is a separate feature controlled by streamRetries.
maxRetries?: number| Name | Type | Description |
|---|---|---|
maxRetries | number | Maximum number of retries. The default is 2; use 0 to disable retries. |
maxRetries sets the maximum number of retry attempts for a request.streamRetries separately for recoverable provider errors detected after streaming begins.maxRetries does not enable recovery for provider errors that arrive after streaming starts.const result = await generateText({
model: 'openai/gpt-4o',
prompt: 'Write a haiku about retries.',
maxRetries: 3,
});This requests up to three retries when starting the model call.
Transient provider or network failures occur before a model call starts.
A request must fail immediately without another attempt.
A streaming response can emit a provider error after streaming begins.
streamRetriesRequestOptionsgenerateTextonError