Skip to main content
Driftstack DRIFTSTACK

Idempotency keys

Network requests fail. Mobile keyboards double-tap submit buttons. A retry-on-timeout that re-sends a POST can mint a second order the customer never wanted. The Driftstack API uses the standard Idempotency-Key request header to make safe-to-retry mutations actually safe.

How it works

Send a unique opaque token on the Idempotency-Key request header. The first request with a new token is processed normally. Any subsequent request to the same endpoint with the same token, scoped to the same caller, returns the original response verbatim — same body, same Location, same minted IDs.

POST /v1/billing/crypto-checkout
Authorization: Bearer $KEY
Idempotency-Key: 7b3f2e0c-1b6a-4cf3-aa6d-9c2c1f8a1b22
Content-Type: application/json

{
  "product": "team_manual",
  "price_cents": 4900,
  "price_currency": "USD"
}

When the response is a replay (i.e. the server is returning a previously-minted result rather than performing the work again), it sets:

Idempotent-Replayed: 1

Most clients can ignore this header; it's useful for analytics and for debugging "why does my dashboard show this order twice".

Where it applies

Future write endpoints will adopt the same convention; this page will enumerate them. Read-only endpoints do not consult the header.

Choosing a key

Scope + lifetime

Errors

We do not reject replays where the request body differs from the original — if you send k1 with price_cents=4900 first, then k1 with price_cents=9900, you still get the original 4900-cent order back. The server records the mismatch and surfaces it as body_mismatches on the admin GET /v1/admin/crypto-orders/idempotency-metrics counter, so support can spot client bugs where a key is being reused across intents. Mint a fresh key per intent and this is a non-issue.

Related