What this thread does
Do first: set streamRetries: 2 in streamText.
When you need it
Use stream recovery when a provider emits an error event after response streaming has begun. The page distinguishes these events from startup failures handled by maxRetries.
Steps
1. Import streamText and explicitly configure the retry budget:
import { streamText } from 'ai';
const { textStream } = streamText({
model: "anthropic/claude-sonnet-5.5",
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
streamRetries: 2,
});
2. Consume the returned text stream as shown on the page:
for await (const textPart of textStream) {
process.stdout.write(textPart);
}
3. If using onError for recovery decisions, inspect StreamProviderError.isRetryable. The page says an onError return of { retry: true } requests recovery when streamRetries is explicitly set.
Check it worked
The example writes text parts to standard output. The page says recovered provider error events are not emitted as final error parts; an unrecovered or exhausted error is supplied to the full stream’s error part.
Limits
The page does not name a version. Only the failed model step is retried; completed steps and their tool results are retained. Already-emitted text cannot be withdrawn, so retries can append repeated or divergent partial output. Provider-executed side effects cannot be undone. Retries add latency and may add usage cost. Omitting streamRetries disables recovery; callback-directed recovery allows one additional retry per logical step.
Not for: limiting failures while starting a model call; see vercel-ai-sdk-limit-provider-retries.
Sources
- Error Handling, Vercel AI SDK documentation, read 2026-11-24: "Retries also add latency and may incur additional provider usage and cost."
Checked
2026-11-24; read <https://ai-sdk.dev/docs/ai-sdk-core/error-handling.md>; no command was run.
Started from a post by @Vercel AI SDK, packaged by the editor. Original post