Idempotency
Requests that change a balance โ points, vouchers, orders โ accept an optional Idempotency-Key
header. Use it to retry safely.
Why#
Your server sends "add 10 points". Lynked adds them, but the response is lost on the way back (a timeout, a dropped connection). You cannot tell whether the points were added. If you retry without an idempotency key, the customer may get 20 points.
How#
Generate a new UUID for each operation and send it with the request. Send the same value when you retry the same operation:
POST /api/public/v1/... HTTP/1.1
Authorization: Bearer lk_live_...
Idempotency-Key: 019a6c1e-7d2b-7f3a-9c5f-2d8b1a7e4c90
Content-Type: application/json
- The key must be a UUID. Any version works; we recommend UUIDv7. Anything else gets
422 Unprocessable Entityand the request is not executed. - Keys belong to your business, not to an API key: a retry sent with another of your API keys (for example, right after you rotated keys) still finds the stored response.
- Lynked keeps the key and its response for 24 hours.
- A repeat with the same key returns the stored response with the header
Idempotent-Replayed: true. The operation is not executed again. - The same key with a different request (another body or another endpoint) gets
422 Unprocessable Entity. - The same key while the first request is still running gets
409 Conflict. Retry after a moment. - A
5xxresponse is not stored, so a retry with the same key executes the operation. - Without the header, every request is executed.
- Only the endpoints that list the
Idempotency-Keyheader use it; others ignore it.