Crux
GuidesRouting & Fallback

Retry

Retry one model before another routing primitive handles failure.

retry() repeats the same model with a bounded attempt count. Use it for transient provider errors before fallback moves sideways.

import { fallback, retry } from "@use-crux/core/routing";

const resilient = fallback([
  retry(gpt5, {
    id: "gpt5-retry",
    attempts: 2,
    backoff: "exponential",
    on: ["rate_limit", "timeout"],
  }),
  sonnet,
]);

retry() composes with every other routing primitive and preserves the child model's routing context requirements.

Retry receipts include every attempt:

result.routing?.trace;
// [{ kind: 'retry', id: 'gpt5-retry', model: 'gpt-5', attempts: [{ status: 'error' }, { status: 'ok' }] }]

Use timeout.totalMs on the generate() or stream() call when a whole routed call needs one hard wall across retry and fallback attempts.

On this page

No Headings