> ## Documentation Index
> Fetch the complete documentation index at: https://acme-c84a37e5.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Retry Logic

> Retries with delay, jitter, and backoff strategies

## Main options

* `retries`: number of retries
* `retryDelay`: number, function, or based on attempt and last error
* `jitter`: randomness to prevent thundering herd
* `backoffStrategy`: `linear`, `exponential`, `fibonacci` or function
* `maxDelay`: upper limit of delay
* `shouldRetry`: decides whether to continue retrying
* `onRetry`: observability per attempt

## Basic example

```typescript theme={null}
import { run } from "tryo";

const r = await run(() => fetch("/api"), {
  retries: 3,
  retryDelay: 300,
  jitter: 0.5,
  backoffStrategy: "exponential",
});
```

## Dynamic delay

```typescript theme={null}
const r = await run(() => fetch("/api"), {
  retries: 5,
  retryDelay: (attempt) => attempt * 200,
  maxDelay: 2000,
});
```

## Retry control with `shouldRetry`

```typescript theme={null}
const r = await run(() => fetch("/api"), {
  retries: 5,
  shouldRetry: (attempt, error, ctx) => error.code !== "ABORTED" && ctx.elapsedTime < 5000,
});
```

## Observability with `onRetry`

```typescript theme={null}
const r = await run(() => fetch("/api"), {
  retries: 3,
  onRetry: (attempt, error, nextDelay) => {
    console.log(attempt, error.code, nextDelay);
  },
});
```
