> ## 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.

# Safe Retries

> Failed calls are not charged, and exactly-once is yours to enforce.

## Failed Requests

Usage is reserved before each call and settled only when the call succeeds and produces usage. A timeout, dropped connection, or `5xx` before that releases the reservation. See [How the API Works](/api/get-started/how-nito-works).

## `Idempotency-Key`

On public inference, a supplied `Idempotency-Key` is validated as a UUID but not used to deduplicate. Each request runs and is metered separately.

## Retrying

1. Retry timeouts, dropped connections, `429`, `502`, and `503` with backoff. On `429`, wait for `Retry-After`.
2. A call that completed on the server but whose response was lost will run again on a blind retry. When you cannot tell, check state first.
3. For an operation that must not run twice, record a client-generated operation ID once the call succeeds and check it before retrying.

```python wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
import time, httpx

def call_with_retry(url, payload, headers, attempts=4):
    for i in range(attempts):
        try:
            r = httpx.post(url, json=payload, headers=headers, timeout=60)
            if r.status_code in (429, 500, 502, 503, 504):
                raise httpx.HTTPStatusError("retryable", request=r.request, response=r)
            r.raise_for_status()
            return r.json()
        except (httpx.TransportError, httpx.HTTPStatusError):
            if i == attempts - 1:
                raise
            time.sleep(2 ** i)  # exponential backoff
```

## Related

<CardGroup cols={2}>
  <Card title="How the API Works" icon="gears" href="/api/get-started/how-nito-works">
    Reserve, run, settle.
  </Card>

  <Card title="Error Reference" icon="book" href="/api/api-reference/errors-and-rate-limits/error-codes">
    The `code` families.
  </Card>

  <Card title="Rate Limits" icon="gauge" href="/api/api-reference/errors-and-rate-limits/rate-limits">
    `Retry-After` and the limit headers.
  </Card>

  <Card title="Uptime and Fallbacks" icon="life-ring" href="/api/features/best-practices/uptime-and-fallbacks">
    Failover without weakening privacy.
  </Card>
</CardGroup>


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