# Idempotency

> Retry Besday API POST requests safely with an Idempotency-Key header: how keys are matched, replayed and expire after 24 hours.

Source: https://besday.com/docs/api/idempotency · Updated 2026-12-03 · OpenAPI: https://besday.com/api/v1/openapi.json

Send an `Idempotency-Key` header with every POST. If the network drops and you retry with the same key, Besday returns the first answer instead of creating a second order or paying twice.

```bash
curl -X POST "https://besday.com/api/v1/orders/prj_…/pay" \
  -H "Authorization: Bearer $BESDAY_API_KEY" \
  -H "Idempotency-Key: 7d0e3b0a-1c55-4d2b-9a43-2f7c3f1b9e10"
```

## How it works

- A key is 1–255 visible ASCII characters; a UUID per logical operation is ideal.
- Keys are remembered per brand for 24 hours.
- A retry with the same key and the same body gets the stored status and body, plus the header `Idempotent-Replayed: true`.
- The same key with a different method, path or body is refused: 409 `idempotency_key_reused`.
- While the first request is still running, a retry gets 409 `idempotency_in_progress`; retry a second later.
- Server errors (5xx) are not stored, so a retry with the same key runs again.

> Paying is also protected without the header: an order can only be paid once (409 `already_paid`). Approving is naturally idempotent.
