Vezmo App

Accounts API · Accounts API

Idempotency and retries

A network can drop an answer after the request arrived. An Idempotency-Key lets you send the same call again safely: we run it once, and every retry with the same key gets the first answer back. Use it on every Accounts API write.

  • Idempotency-Key: 1–255 printable ASCII characters. A UUID is a good choice, or your own id for the thing (a bill number), as long as it is never used for anything else.
  • Required on POST /recipients, POST /quotes and POST /transfer-requests: without it, 400 idempotency_key_required. Optional on the other writes (PATCH and DELETE /recipients/{id}, cancelling a request).
  • A key belongs to your business and the key's mode (test or live), whichever of your keys sends it. Keys are kept for 30 days.
  • One key per logical call: the same key on every retry of it, a new key for a new payment or a new recipient.
Request
# Make the key once, keep it with the payment, and send the same one on every retry.
IDEMPOTENCY_KEY=$(uuidgen)

curl -X POST https://api.vezmo.com/api/v1/transfer-requests \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Vezmo-Version: 2026-11-14" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "recipientId": "rcp_cm3w2k9aa0004", "amount": 420000, "currency": "USD", "side": "send" }'

What happens on a second call with the same key

  • Same body, first call finished: the first status and body are returned as they were, with Idempotent-Replayed: true. Nothing runs twice.
  • Different body: 409 idempotency_key_reused with resourceId, the object the first call made.
  • First call still running (under 5 minutes): 409 idempotency_request_in_progress with Retry-After: 1. Wait and send it again.
  • First call cut short (still running after 5 minutes, or it ended in a 5xx with nothing saved): the retry runs it again.
A replay
HTTP/1.1 201 Created
Idempotent-Replayed: true
Content-Type: application/json

{ "success": true, "data": { "id": "trq_cm3w4a2cc000b", "object": "transfer_request", "status": "pending_approval", "…": "…" } }
409 idempotency_key_reused
{
  "success": false,
  "errors": [
    {
      "code": "idempotency_key_reused",
      "message": "This Idempotency-Key was already used with a different request.",
      "resourceId": "trq_cm3w4a2cc000b",
      "help": "https://user.vezmo.com/docs/v1/errors#idempotency_key_reused"
    }
  ],
  "requestId": "…"
}

Which answers are kept

  • Successes and refusals after we started (for example possible_duplicate, limit_exceeded, recipient_exists) are kept and replayed. If you fix the cause, such as a cap that has reset, send it with a new key.
  • Not kept: a 400 validation_failed on the body, and refusals before the call starts (401, 403, 429). Correct the call and send it again with the same key.
  • A 5xx with nothing saved isn't kept either: retry with the same key.
  • A recipient or transfer request and its kept answer are saved together, so a retry never finds one without the other.

Which answers to retry

  • Retry, with the same key: 429, any 5xx, and 409 idempotency_request_in_progress. Wait for Retry-After when it is there, else back off (1 s, 2 s, 4 s…), and stop after a few tries.
  • Don't retry any other 4xx unchanged: it is a final answer. Read its code (see Errors).
  • A dropped connection with no answer at all: retry with the same key, which is what the key is for.
Node.js
import { randomUUID } from "node:crypto";

/**
 * One logical call = one Idempotency-Key, made once and sent on every try. Retries only what can succeed later:
 * 429, 5xx and idempotency_request_in_progress. Everything else is a final answer.
 */
export async function vezmoWrite(method, path, body, key = randomUUID(), tries = 4) {
  for (let attempt = 0; ; attempt++) {
    const res = await fetch(`https://api.vezmo.com/api/v1${path}`, {
      method,
      headers: {
        Authorization: `Bearer ${await accessToken()}`,
        "Vezmo-Version": "2026-11-14",
        "Idempotency-Key": key,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(body),
    });
    const json = await res.json();
    if (res.ok) return { data: json.data, replayed: res.headers.get("idempotent-replayed") === "true" };
    const code = json.errors?.[0]?.code;
    const retry = res.status === 429 || res.status >= 500 || code === "idempotency_request_in_progress";
    if (!retry || attempt + 1 >= tries) throw Object.assign(new Error(json.errors?.[0]?.message), { code, key });
    const wait = Number(res.headers.get("retry-after") ?? Math.min(30, 2 ** attempt));
    await new Promise((r) => setTimeout(r, wait * 1000));
  }
}
Python
import time
import uuid
import requests

RETRY = {"idempotency_request_in_progress"}

def vezmo_write(method, path, body, key=None, tries=4):
    key = key or str(uuid.uuid4())  # one key per logical call, sent on every try
    for attempt in range(tries):
        res = requests.request(
            method,
            f"https://api.vezmo.com/api/v1{path}",
            json=body,
            headers={
                "Authorization": f"Bearer {access_token()}",
                "Vezmo-Version": "2026-11-14",
                "Idempotency-Key": key,
            },
            timeout=30,
        )
        data = res.json()
        if res.ok:
            return data["data"]
        code = (data.get("errors") or [{}])[0].get("code")
        if not (res.status_code == 429 or res.status_code >= 500 or code in RETRY) or attempt + 1 == tries:
            raise RuntimeError(f"{code}: {key}")
        time.sleep(float(res.headers.get("Retry-After", min(30, 2 ** attempt))))

Idempotency isn't the duplicate check

A key only catches a retry of the same call. Two different calls for the same payment (two keys) are caught by the duplicate check instead: a transfer request for the same recipient, amount and currency as one in the last 24 hours answers 409 possible_duplicate, unless you send allowDuplicate: true. See Transfer requests.