The AI SDK retries failed provider calls automatically (429 rate limits, 5xx, network blips). RetryError means every attempt failed and here is the last error.

import { RetryError, generateText } from 'ai';

try {
  await generateText({ model, prompt: 'Hi', maxRetries: 5 });
} catch (error) {
  if (RetryError.isInstance(error)) {
    console.error('attempts:', error.attempts, 'last:', error.lastError);
  }
}

What to know:
1. maxRetries is a per-call option on generateText/streamText. The default is small; raise it for batch jobs, lower it (or 0) for latency-sensitive chat where a fast failure beats a slow one.
2. RetryError wraps the last attempt's error. Always log error.lastError, not just the RetryError itself, or you will chase the wrong cause.
3. 4xx errors other than 429 are generally not retried. A RetryError whose lastError is a 401 means your key is wrong, not that the provider is flaky. Do not raise maxRetries to fix a 401.
4. For streams, retries apply to establishing the stream. Mid-stream failures surface as StreamProviderError parts, not RetryError.
5. Add jittered backoff around your own call loop for 429-heavy workloads; the SDK's built-in retry is per call, and a tight loop of calls can still hammer the provider.
6. If you see RetryError in a cron or queue worker, alert on it. It means sustained provider failure, and your dead-letter handling should kick in.