Retry Transient Model Calls

You want an agent route to retry transient model and provider failures automatically. Here's how.

The code

import { agent } from "@dawn-ai/sdk"
 
export default agent({
  model: "gpt-5-mini",
  retry: { maxAttempts: 5, baseDelay: 500 },
  systemPrompt: "Summarize the document the user provides in three bullet points.",
})

Notes

  • Per-route, not global. Each agent() declares its own retry. Different routes can have different policies.
  • Transient model/provider errors only. Rate limits (429), server errors (500/502/503), network timeouts, and OpenAI overloaded/server_error are retried. Invalid API keys, missing models, and schema validation errors fail immediately.
  • Exponential backoff with jitter, capped at 10s. For non-stream fallback, delay = min(baseDelay * 2^n + jitter, 10s). Lowering baseDelay makes the first retry faster.
  • maxAttempts: 1 disables retry. The default is 3 if retry is omitted entirely.
  • Streaming routes only retry before the first event. Once an event has streamed, the response is committed. Agent retry covers transient model/provider execution before that point; applications needing tool retry implement it locally, as in the example above.