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:

Create a payout, safe to retry
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.

Operations that take an Idempotency-Key header
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.

  1. Your serverStridge APIPOST /v2/payouts · Idempotency-Key: K
  2. Stridge APIRemembered resultsK is in flight
  3. Stridge APICreates the payout
  4. Stridge APIYour server201 Created
  5. Stridge APIRemembered resultsRemembers the result for 24 hours
Stridge marks the key in use while the request runs, responds, and remembers the result under the key 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: true and its own Request-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 400 idempotency_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 409 idempotency_key_in_use at 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 400 header_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 404 and a 500.
  • 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 409 conflict.
  • A 429 rate limit.
  • A 403 step_up_required.
  • Any response that carries Retry-After.
  • A response whose body is larger than 64 KiB.
  • A 500 from an operation whose page says its 500 is 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 (after Retry-After), a 409 idempotency_key_in_use and a 5xx. 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-Key replays the first 201.
  • A new create, under a new key or none, returns 409 payout_reference_taken when it names a reference_id the vault still holds. error.payout names the payout that holds it.
  • Without an Idempotency-Key, reference_id is 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:

PayoutIts reference_id
In flightHeld
confirmedHeld
expiredHeld
Rejected by you before its payment startedFreed
failed, having certainly sent nothingFreed

See POST /v2/payouts.