Idempotency
How to retry requests with an Idempotency-Key, what a retry returns, and when not to resend.
Idempotency lets you retry an API request without creating a duplicate charge, within the rules below. Before resending, read Retrying safely: some requests must not be resent.
How it works
Include an Idempotency-Key header with a client-generated UUID on every state-mutating request:
-H "Idempotency-Key: idem_550e8400-e29b-41d4-a716-446655440000"Cresora stores the key and a successful (2xx) result for 24 hours, scoped to your partner account. An error response is not stored: a same-key retry after one runs the request again, unless Cresora recorded the attempt (see Retrying safely). If you retry with the same key after a success:
- The original result is returned immediately — no second transaction is created
- The HTTP status code is the same as the original response
- An
X-Idempotent-Replay: trueresponse header indicates the cached result was returned
After 24 hours
The cached response expires after 24 hours. What a retry does after that depends on the operation:
POST /api/v1/transactionskeeps answering. The first such retry of the same request returns the transaction recorded under the key, in its state at that moment, as a plain200withoutX-Idempotent-Replay. That answer is cached for 24 hours, so a further retry returns the same snapshot:GETthe transaction for its current state. A different request is refused with422 idempotency_key_reusedwhen Cresora can compare it with the original; when it cannot, Cresora compares only the main fields, so a changed request can still be answered with the original. ACAPTURE_ALLthat cannot be compared is refused with422even when it is identical: check whetherGETon each authorization it named shows it has leftAUTHORIZED(CAPTUREDor later, such asSETTLED) instead of resending.- Any other write: do not rely on a key to dedupe a retry that comes later than 24 hours. Some operations keep honouring a key beyond that, and one with no lasting dedupe may repeat the action.
Retrying safely
These apply at any time, not only after 24 hours:
- Never reuse a key for a different request. "The same request" means the same method and URL and a byte-identical body: store the exact bytes you sent and resend those. A body that is only re-serialized (another field order or spacing) counts as a different request: it is refused with
422 idempotency_key_reusedwhen Cresora can compare it with the original, and otherwise it may run again. A422 idempotency_key_reusedon a retry does not mean the first request failed: resend the original bytes with the same key, and use a new key only for a request that is genuinely different. If the same bytes are refused again, stop resending and check what the key created (for aCAPTURE_ALL, whetherGETon each authorization it named shows it has leftAUTHORIZED:CAPTUREDor later, such asSETTLED). - A
502 gateway_outcome_unknownwithreplay: "same_idempotency_key"in the body: Cresora recorded the attempt as pending. Never resend it automatically and never under a new key. Resend the identical request with the same key to obtain the transaction: it is not sent to the gateway again, and it is never a second charge. ThenGETthe transaction for its final state. - A
502 gateway_outcome_unknownwithout areplaymember: Cresora does not promise that a resend is safe. Do not resend automatically, never under a new key, and if the outcome cannot be established contact support quoting theerror_id.
A webhook secret is shown once. Creating a webhook subscription and rotating its secret have no cached response, so from the first retry, not only after 24 hours, a retry with the same key returns secret: null. Both are exceptions to "the original result is returned". If you lost a secret, rotate it with a new key, and update your receiver right away: Cresora signs with the new secret straight after the rotation succeeds (a delivery signed with the old one can still arrive for about 5 minutes), so deliveries fail until it is deployed (see rotating your signing secret). A retry with the key of the latest rotation does not rotate again, however long ago that was, and only the latest rotation's key is remembered: retrying an older rotation's key rotates again.
Key format
1–128 characters of letters, digits, . _ : -. A key longer than 128 characters is rejected with 400 idempotency_key_too_long, and a key with any other character with 400 validation_error — note that padded base64 (+ / =) is not accepted, base64url is. A UUIDv4 is the recommended form:
"Idempotency-Key": "idem_" + crypto.randomUUID()Reserved prefixes are rejected with 400 idempotency_key_reserved: hpp:, hpp-contract: and recurring: (Cresora's own server-minted keys), and rb:, inv-charge:, inv-installment: (reserved by the payment gateway). Don't namespace your keys with a trailing colon that lands in one of these.
Conflict detection
If you use the same key with a different request (another path or body), Cresora rejects the retry with 422 idempotency_key_reused when it can compare it with the original (see Retrying safely and After 24 hours):
{ "code": "idempotency_key_reused", "message": "Idempotency-Key already used with a different request body." }This is intentional — it prevents accidentally reusing a key that was already tied to a different payment. If the first request with a key is still being processed, an identical second request is refused with 409 idempotent_request_in_flight and Retry-After: 2: retry after that. A different request on that key is refused with 422 idempotency_key_reused. A second code, 409 idempotency_key_conflict (retryable: true), means a concurrent request with the same key won the write at the database. Retry with the same key to receive its result (a webhook secret is not returned again).
Idempotency-Key is required on every write — POST /api/v1/transactions and the other POST, PUT and PATCH operations — in the sandbox exactly as in production. A missing header returns 400 idempotency_key_required. There is no sandbox exemption.
Which endpoints require it?
| Endpoint | Idempotency-Key |
|---|---|
POST /api/v1/transactions (all types — SALE, REFUND, CAPTURE, …) | Required |
Other POST, PUT and PATCH write operations | Required |
GET requests | Not applicable |
DELETE requests | Not required — DELETE is idempotent at the HTTP level (RFC 9110) |