Idempotency
A network can drop the connection after Stridge has acted on your request but before you read the response. Retrying a read is harmless. Retrying a payout is not. An operation is idempotent (opens in a new tab) when doing it twice has the same effect as doing it once. The Idempotency-Key header makes a POST idempotent: send the same key on a retry, and Stridge returns the first result instead of acting twice:
curl -X POST "https://api.stridge.com/v2/payouts" \
-H "Authorization: Bearer $STRIDGE_SECRET_KEY" \
-H "Idempotency-Key: 6f1c2a9e-3b7d-4c55-9a0e-8f2d1b4c7e90" \
-H "Content-Type: application/json" \
-d '{
"vault_id": "7c1e0a94-31d6-4a52-9f83-2b4c5d6e7f80",
"reference_id": "order_1042",
"to_address": "0x2222222222222222222222222222222222222222",
"network_symbol": "ethereum",
"asset": "USDC",
"amount": { "amount": "100500000", "amount_decimal": "100.5", "decimals": 6, "asset": "USDC" }
}'Make one key per logical operation, such as a UUID generated when your code decides to pay. Store it with the operation, and send the same key on every retry.
Which operations take a key
Every POST takes a key. On most it is optional. GET, PATCH and DELETE take no key.
The sandbox test helpers that simulate deposits and payouts require one, such as POST /v2/sandbox/test-helpers/vault/deposits and POST /v2/sandbox/test-helpers/payouts. Each of them changes the simulated world, so a call without a key returns 400 header_invalid.
| Key required6 |
|---|
Simulate a deposit to a deposit addressPOST/sandbox/test-helpers/uda/deposits |
Simulate a deposit to a vaultPOST/sandbox/test-helpers/vault/deposits |
Simulate a deposit to an address the environment holdsPOST/sandbox/test-helpers/address/deposits |
Simulate a payoutPOST/sandbox/test-helpers/payouts |
Release a held payoutPOST/sandbox/test-helpers/payouts/{payout_id}/release |
Fail a held payoutPOST/sandbox/test-helpers/payouts/{payout_id}/fail |
| Key optional10 |
Retry a settlementPOST/settlements/{id}/retry |
Create a deposit addressPOST/uda |
Create a payoutPOST/payouts |
Quote a routed payoutPOST/payouts/quotes |
Reject a payoutPOST/payouts/{payout_id}/reject |
Create a webhook endpointPOST/webhook-endpoints |
Ping a webhook endpointPOST/webhook-endpoints/{endpoint_id}/ping |
Rotate a webhook endpoint's signing secretPOST/webhook-endpoints/{endpoint_id}/rotate-secret |
Re-enable a webhook endpointPOST/webhook-endpoints/{endpoint_id}/enable |
Move a sandbox endpoint's failing_since backPOST/sandbox/test-helpers/webhook-endpoints/{endpoint_id}/failing-since |
How a key behaves
A key lets you retry without fear of doing the work twice. Follow one key through each case: a first request, a retry after a lost response, a retry while the first is still running, the key on a different request, and the key after it expires.
- Your serverStridge APIPOST /v2/payouts · Idempotency-Key: K
- Stridge APIRemembered resultsK is in flight
- Stridge APICreates the payout
- Stridge APIYour server201 Created
- Stridge APIRemembered resultsRemembers the result for 24 hours
- The same key with the same parameters returns the first result, status and body both. Nothing runs a second time, so a retry after a dropped connection is safe whether or not the first attempt landed. A replayed response carries
Idempotency-Replay: trueand its ownRequest-Id. - Parameters are compared by value, not byte for byte. The order of query parameters or JSON members, spacing and escaping make no difference. Any changed value does.
- The same key with different parameters returns
400idempotency_key_reused. So does the same key sent to another operation. A key names one request, so reusing it for another is a bug in your client, not a retry. - A retry while the first request is still running returns
409idempotency_key_in_useat once. Retry again after the first request has finished. - Keys last 24 hours. After that, the same key starts a new request.
- Keys belong to one environment. All secret keys of an environment share its idempotency keys, so a retry sent with a rolled secret key still finds the first result. A key used in live never matches a sandbox request. After a sandbox reset, a key used before the reset runs afresh.
- A key is at most 255 characters. A longer one returns
400header_invalid.
What is remembered
A retry replays the first result only if Stridge remembered it. Stridge remembers the result of every attempt that began to run. A result that is not remembered lets the same key run again once you fix the cause.
Remembered: a retry replays it
- Every attempt that began to run, success or failure, including a
404and a500. - For the sandbox test helpers that simulate deposits and payouts, only the result of a simulation that ran.
Not remembered: a retry runs afresh
- A validation error (
400,422). - A
409conflict. - A
429rate limit. - A
403step_up_required. - Any response that carries
Retry-After. - A response whose body is larger than 64 KiB.
- A
500from an operation whose page says its500is not remembered. - A refused call to a sandbox test helper that simulates deposits or payouts.
What a first attempt did still stands, even when its result is not remembered. If a payout create took its reference_id, the retry returns 409 payout_reference_taken, and error.payout names the payout it made.
Two operations return a webhook signing secret: POST /v2/webhook-endpoints and POST /v2/webhook-endpoints/{endpoint_id}/rotate-secret. A retry under the same key within 24 hours replays the same secret, so a lost response never means a lost secret. The replay is the first response exactly as it was, even if a later rotation has replaced that secret.
Retrying well
A good retry loop recovers from every transient failure and never turns a bug into a duplicate.
- Retry on a network error, a timeout, a
429(afterRetry-After), a409idempotency_key_in_useand a5xx. Use exponential backoff with jitter. - Stop within the key's 24 hours. After that, the same key starts a new request. So before you try again, read the object to learn whether the first attempt acted. Send a new request with a new key only if it did not.
- Do not retry unchanged on any other
4xx. The request itself is wrong. - Keep the key across every retry of one operation, and make a new one for each new operation.
Payouts and reference_id
Payouts have a second guard against paying twice: your reference_id.
- A retry under the same
Idempotency-Keyreplays the first201. - A new create, under a new key or none, returns
409payout_reference_takenwhen it names areference_idthe vault still holds.error.payoutnames the payout that holds it. - Without an
Idempotency-Key,reference_idis what keeps a retry from paying twice.
A payout holds its reference while it may still pay, or may have paid. Only a payout that certainly moved no money frees it:
| Payout | Its reference_id |
|---|---|
| In flight | Held |
confirmed | Held |
expired | Held |
| Rejected by you before its payment started | Freed |
failed, having certainly sent nothing | Freed |
See POST /v2/payouts.