Skip to content

Idempotency ​

To prevent retries from causing duplicate card opens / duplicate charges, write endpoints require an Idempotency-Key header.

Which Endpoints Require It ​

EndpointRequired?
/api/v1/openapi/card/apply✅ Yes
/api/v1/openapi/card/recharge✅ Yes
/api/v1/openapi/cardholder/files/upload / create / update / delete / submit / kyc/init / kyc/cancel✅ Yes (v1.6, see Cardholders)
/card/freeze / /card/unfreeze / /card/close❌ No — protected by the card state machine (a repeat returns card_already_frozen / card_not_frozen / card_is_closing / card_already_closed)
All /list and /info endpoints, /card/sensitive/send_code, /card/first_deposit/preview, /cardholder/requirement / list / detail / check / legacy_cards❌ No
http
Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000
ConstraintValue
Length≤ 128 chars
CharsetVisible ASCII only (0x21–0x7E, no spaces); UUID v4 / ULID recommended
ScopePer AppID — one key space is shared by all write endpoints (/card/apply, /card/recharge and the cardholder write endpoints), so never reuse a key across endpoints
Dedup window24 hours from the first completed response
MissingHTTP 200 / 40000 openapi_idempotency_key_required
Too longHTTP 200 / 40000 openapi_idempotency_key_too_long
Bad charactersHTTP 200 / 40000 openapi_idempotency_key_invalid_chars
Same key, different bodyHTTP 409 / 40900 openapi_idempotency_key_conflict
Same key, first request still runningHTTP 409 / 40900 openapi_idempotency_key_in_progress

The header checks run before anything is stored: after an openapi_idempotency_key_* header error, fix the header and resend.

"Same body" means the byte-identical raw request body (the server hashes the exact bytes you sent — the same bytes as the BODY_SHA256_HEX you sign). Re-serializing the JSON with a different key order or whitespace produces a different body and gets openapi_idempotency_key_conflict. Store the exact body bytes together with the key and resend those bytes on retry. For the multipart /cardholder/files/upload this includes the boundary — a re-encoded form is a different body.

If the idempotency store is temporarily unavailable, the request is not executed and you get HTTP 200 / 50000 openapi_internal_error; nothing is stored, so retrying with the same key and body is safe.

Server Behavior ​

Same key + same body ​

Returns a copy of the stored response (the original HTTP status and body, byte for byte). Does not trigger a second card open or charge.

If the first request with this key is still being processed, the server does not wait for it: the second request immediately gets 409 / 40900 openapi_idempotency_key_in_progress. Retry the same key + same body a few seconds later to receive the stored result.

The replayed response carries an extra response header so you can tell it apart from a fresh call:

http
X-Idempotent-Replay: true

Detecting replays

Treat the X-Idempotent-Replay: true header as informational. Either way the response body is the authoritative source of truth — but the header is useful for metrics and debugging ("this attempt actually hit the server but I retried after a network blip").

Which responses are replayed ​

The server stores the response whenever the original call returned an HTTP 2xx status — and that includes business errors, which are sent with HTTP 200:

First responseStored for 24 h?Same key + same body again
Success (code: 0)✅Replays the success
Business error, HTTP 200 (40000 / 40001 / 50000, e.g. insufficient_balance, card_number_not_ready, openapi_recharge_failed)✅Replays the same error — the request is not re-executed
HTTP 404 card_not_found, HTTP 403, HTTP 409, HTTP 429, HTTP 401, HTTP 500 crash❌Executed again

After fixing a business error, use a new key

If /card/recharge returned insufficient_balance and you then top up the wallet, resending the same key keeps returning insufficient_balance for 24 hours. Once the cause is fixed, send the corrected request with a new Idempotency-Key.

Exception — 50000 openapi_recharge_failed / openapi_apply_card_failed: an order may or may not have been created. Check /card/transactions/list or /cards/list (and your webhooks) before sending a new key, so you don't open or charge twice.

Recharge outcome unknown

When the recharge provider times out, /card/recharge returns a normal success with status: 1 (processing) — that success is stored and replayed like any other. The final result arrives via card.recharged / card.recharge_failed. Do not resend with a new key.

Captured response size

The server caches at most 256 KB of the response body. The current OpenAPI responses are well under that ceiling, so this should never be a concern in practice — flagged only for completeness.

Same key + different body ​

Returns 409 / 40900 openapi_idempotency_key_conflict. The server refuses to process. Client should switch keys or fix the body.

Different keys + same body ​

Treated as two independent requests — opens two cards / charges twice. By design — idempotency is keyed by the header, not the body.

Don't use a body hash as the key

Using "request body hash" as the Idempotency-Key would deduplicate "user clicks recharge twice for the same amount" into a single charge. The key represents one business intent; generate a new key for each new business intent.

Client SDK pattern ​

python
import uuid

def apply_card(header_id, package_id):
    key = str(uuid.uuid4())  # new key per business call
    return call("/api/v1/openapi/card/apply",
                {"header_id": header_id, "package_id": package_id},
                idempotency_key=key)

Async-task pattern ​

If your "apply card" task is retried by a job queue on network failure, bind the key to the task record:

python
def open_card_task(task_id, header_id, package_id):
    # All retries of the same task use the same key
    key = f"openapi:apply:{task_id}"
    return call("/api/v1/openapi/card/apply", {...}, idempotency_key=key)

That way, even if the task is retried N times, Brand opens at most one card. Remember that a stored business error is replayed too: when the task fails with a code other than 0, decide whether to fix the cause and create a new task (new key) instead of retrying the old one.

Relationship with Signatures ​

Idempotency-Key is not part of the signing input (the signature covers method/path/query/timestamp/nonce/body sha256). Each request still needs a fresh nonce. They are two independent mechanisms:

MechanismProtects against
NonceAn attacker capturing a signature and replaying the request
Idempotency-KeyYou safely retrying after a network failure

Coordinating both: when the client retries the same business call, use the same Idempotency-Key + new Nonce + new Timestamp + new Signature.

Error Responses ​

Missing (HTTP 200 / 40000) ​

json
{
  "code": 40000,
  "message": "Missing Idempotency-Key header",
  "error_key": "openapi_idempotency_key_required"
}

Conflict (HTTP 409 / 40900) ​

json
{
  "code": 40900,
  "message": "Idempotency-Key conflict: same key with different request body",
  "error_key": "openapi_idempotency_key_conflict"
}

In progress (HTTP 409 / 40900) ​

json
{
  "code": 40900,
  "message": "Another request with the same Idempotency-Key is still in progress, please retry shortly",
  "error_key": "openapi_idempotency_key_in_progress"
}

Released under MIT-equivalent terms.