> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trynito.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Backoff

> Exponential backoff with jitter, Retry-After, and the upstream circuit breaker.

1. On `429`, wait at least `Retry-After`.
2. On `502`/`503` without `Retry-After`, double the wait each attempt (1s, 2s, 4s, 8s).
3. Add random jitter.
4. Cap attempts and maximum wait, then surface the error with its `X-Request-ID`.

`Retry-After` beats your computed backoff.

## Pseudocode

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
attempt = 0
while attempt < max_attempts:
    response = send(request)
    if response.ok:
        return response
    if not retryable(response.code):
        raise response
    if response.has("Retry-After"):
        wait = response.retry_after_seconds
    else:
        wait = min(base * 2 ** attempt, max_wait)
    sleep(wait + random_jitter())
    attempt += 1
```

Which codes are retryable: [Retry behavior](/api/api-reference/errors-and-rate-limits/retry-behavior).

## Circuit Breaker

After consecutive provider failures the gateway stops routing to that provider for a cooldown window, then probes before reopening. During cooldown you may see `503 unavailable` or `502 provider_error`; an open-circuit rejection never dispatched, so it is safe to retry with backoff.

## Related

* [Retry behavior](/api/api-reference/errors-and-rate-limits/retry-behavior)
* [Rate limits](/api/api-reference/errors-and-rate-limits/rate-limits)
* [Status mapping](/api/api-reference/errors-and-rate-limits/status-mapping)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.