Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Const

Retries

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.

How it works

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.

Syntax

maxRetries?: number

Parameters

NameTypeDescription
maxRetriesnumberMaximum number of retries. The default is 2; use 0 to disable retries.

Key points

  • maxRetries sets the maximum number of retry attempts for a request.
  • It covers failures during model-call startup.
  • Use streamRetries separately for recoverable provider errors detected after streaming begins.
  • This setting belongs to request/transport configuration rather than generation parameters.

Common mistakes

  • Retrying can increase response time and provider charges.
  • Use zero when you need a single attempt.
  • maxRetries does not enable recovery for provider errors that arrive after streaming starts.

Example: Configure model-call retries

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.

When to use it

Recover from transient startup failures

Transient provider or network failures occur before a model call starts.

Disable retries

A request must fail immediately without another attempt.

Configure stream recovery separately

A streaming response can emit a provider error after streaming begins.

  • streamRetries
  • RequestOptions
  • generateText
  • onError

Source: Settings - AI SDK. Checked 2026-10-15.