Skip to main content

Overview

When creating a transaction, a network drop, client timeout, or unexpected 5xx response can leave you unsure whether the operation was processed. Retrying the request without a safeguard can result in duplicate transactions. The Idempotency-Key header lets you retry any transaction-creation POST safely. If Capa receives a request with a key it has already seen, it replays the original response β€” no duplicate transaction is created. The header is opt-in: if omitted, the request is processed normally with no idempotency guarantee.

Supported Endpoints

The header is recognized on the following POST endpoints only. All other endpoints ignore it.

How It Works

  1. Generate a unique Idempotency-Key (UUIDv4 recommended) for each logical operation and include it as an HTTP header.
  2. Capa processes the request and caches the response under the (userId, key) pair.
  3. On retry, send the identical request body with the same key. Capa detects the duplicate and returns the original response β€” the handler is not invoked again.
  4. Failed originals can be retried. If the first attempt resulted in an error (non-2xx), the record is marked FAILED and a subsequent request with the same key reprocesses normally.
  5. The guarantee window is 48 hours. After that the key expires, the record is reclaimed, and the next request is treated as a new operation. It is the caller’s responsibility to avoid duplicates beyond this window.

Header Reference


Behavior Matrix


Errors


Best Practices

  • Generate a fresh UUIDv4 per logical operation. Never hardcode or reuse keys across distinct operations.
  • Persist the key client-side until you receive a confirmed terminal response for that operation.
  • Retry with the identical body. Changing any field in the request body is treated as a different operation and results in a 422.
  • Do not share a key across endpoints for the same user. Keys are scoped to (userId, key), so the same key on a different endpoint collides on a body hash mismatch.
  • Omit the header on GET, PUT, PATCH, and DELETE requests β€” it has no effect on those methods.
  • Plan for the 48-hour window. Retries after expiry are reprocessed as new requests; implement your own deduplication logic for long-lived operations.

Example

If this request times out or fails at the network level, resend the exact same body with the same Idempotency-Key. Capa will return the original response without creating a second transaction.