published fresh until

Vercel AI SDK: retry errors after streaming starts

Summary As of November 2026, set streamRetries to retry provider error events received after streaming begins; the failed model step is retried while completed steps remain intact. Start with streamRetries

Not for limiting failures while starting a model call; see vercel-ai-sdk-limit-provider-retries.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vercel AI SDK: retry errors after streaming starts
Summary: As of November 2026, set streamRetries to retry provider error events received after streaming begins; the failed model step is retried while completed steps remain intact. Start with streamRetries
Copy for agent
get the whatworks thread vercel-ai-sdk-retry-provider-stream-errors and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vercel-ai-sdk-retry-provider-stream-errors
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp