# Idempotency (/fr/docs/idempotency)

A network can drop right after you send a payout. Did it go through or not? With `Idempotency-Key` it doesn't matter: you resend **the same request with the same key** and get the original result, with no second effect.

```bash
curl https://api-sandbox.caibopay.app/v1/payouts \
  -H "Authorization: Bearer $CAIBO_API_KEY" \
  -H "Idempotency-Key: payout-order-5531" \
  -H "Content-Type: application/json" \
  -d '{ "beneficiary_id": "ben_...", "quote_id": "quo_..." }'
```

## How it behaves [#how-it-behaves]

| You send | You receive |
| --- | --- |
| A new key | `201` and the created resource. |
| The same key with the same request | `200`, the same resource in its current state, and the `Idempotent-Replayed: true` header. Nothing is repeated. |
| The same key with a different request | `409 idempotency_key_reused`. |
| No key, where it's required | `400 idempotency_key_required`. |

If two requests with the same key arrive at the same time, the second waits for the first and returns its result.

## Where it's required [#where-its-required]

On every create call that moves money or locks in a price:

<Endpoint method="POST" path="/v1/customers" /> <Endpoint method="POST" path="/v1/quotes" /> <Endpoint method="POST" path="/v1/payouts" /> <Endpoint method="POST" path="/v1/payouts/{id}/cancel" /> <Endpoint method="POST" path="/v1/payout-batches" /> <Endpoint method="POST" path="/v1/withdrawals" /> <Endpoint method="POST" path="/v1/remittances" /> <Endpoint method="POST" path="/v1/funding-accounts" /> <Endpoint method="POST" path="/v1/refunds" /> <Endpoint method="POST" path="/v1/hosted-sessions" />

All other operations ignore the header. Registering the same beneficiary or the same destination account twice already returns the existing record.

## Best practices [#best-practices]

- **One key per business operation**, derived from your own identifier: `payout-order-5531`, `payin-invoice-F-2201`. That way a retry, even days later or from another process, uses the same one.
- Between **8 and 128 characters** from `A-Z a-z 0-9 . _ : -`.
- **Keys don't expire.** A used key stays bound to its original request forever.
- A rejected request (`4xx`) doesn't consume the key: fix it and resend with the same one.
- On `500` or `503`, retry **with the same key**.

<Callout type="warn" title="A payout without funds does consume its key">
If your balance isn't enough, `POST /v1/payouts` responds `201` with `status: failed` and `failure_code: insufficient_funds`. That payout exists and its key has been used. To retry once you have funds, use a new key (and a new quote if you used one).
</Callout>
