Skip to navigation

Idempotency

A network error or timeout can leave you unsure whether a request reached Paid. Send an Idempotency-Key header on POST and PATCH requests and you can retry them without creating a second customer, order or credit grant: Paid runs the request once and returns the same response to every retry.

Sending a key

Generate a unique key for each operation, such as a UUID, and send it in the Idempotency-Key header. Keep the key with the operation so a retry sends the same one.

curl https://api.paid.ai/v1/customers \
-X POST \
-H "Authorization: Bearer $PAID_API_KEY" \
-H "Idempotency-Key: 5f0c7a2e-8d4b-4c1e-9a3f-2b6d8e1f4a70" \
-H "Content-Type: application/json" \
-d '{"name": "Acme Inc"}'

A key is 1 to 255 printable ASCII characters with no spaces. Any other value returns 400 with the invalid_idempotency_key code.

The header is optional, and Paid ignores it on GET and DELETE, which are already safe to repeat.

Retrying a request

When a request arrives with a key Paid has already seen, the result depends on the first request:

First requestRetry with the same key and body
Finished with a 2xx or 4xx responseReturns that stored response, with the Idempotent-Replayed: true header. The operation does not run again.
Still runningReturns 409 with the idempotency_request_in_progress code. Wait, then retry with the same key.
Failed with a 5xx or 429 responseRuns the request again, as if the key were new.

A replay returns the original status code, body and Paid-Version, even if your account’s default version has changed since.

Validation errors are stored like any other response, so fixing the request body means sending a new key.

Reusing a key

A key belongs to one request. Sending it with a different method, path or body returns 409 with the idempotency_key_reused code, and the new request does not run.

Keys are scoped to your organization, so two organizations can use the same key without colliding.

Key expiry

Paid keeps a key and its response for 24 hours from the first request. After that the key is forgotten, and a request that sends it runs as new. Retry within that window.