← BRPix API documentation

Idempotency

Avoid duplicate charges when retrying requests.

Why use idempotency?

A server can process a POST request even when the response never reaches you. If you retry with the original Idempotency-Key, the API can return the saved result without creating a second charge or transfer.

How it works

Include the Idempotency-Key header in every POST request that creates a charge or transfer. Generate a UUID v4 for each distinct operation. The API stores the key and the result in Redis for 24 hours. During that time, repeating a request with the same key returns the saved result with X-Idempotent-Replayed: true.

# Generate one UUID per operation (Bash)
IDEM_KEY=$(uuidgen)

# Use the key in the request
curl -s -X POST https://api.brpix.app/v1/pix/charges \
  --cert cert.pem --key key.pem \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>" \
  -H "Idempotency-Key: $IDEM_KEY" \
  -d '{"amount":"50.00","acquirer_id":""}'

Original and replayed responses

# First request
HTTP/1.1 201 Created
X-Request-ID: req_abcd1234

{
  "id": "a6c5f328-cb82-4a0b-9f1b-885eddf27fd0",
  "status": "PENDING",
  "amount": "50.00000",
  "qr_code": "00020126..."
}

# Second request with the same Idempotency-Key
HTTP/1.1 201 Created
X-Idempotent-Replayed: true
X-Request-ID: req_efgh5678

{
  "id": "a6c5f328-cb82-4a0b-9f1b-885eddf27fd0",
  "status": "PENDING",
  "amount": "50.00000",
  "qr_code": "00020126..."
}
The replayed response contains the original result. Reusing the key while the result is saved prevents the API from creating the resource again.

Key lifetime

When the API saves the response, it stores the key for 24 hours. After that period, the API can process a request with the same UUID as a new operation.

Use a new UUID for every distinct operation, such as a second charge. When retrying the same operation, keep its original key.

Missing header

The header is required to create charges and transfers. Omitting Idempotency-Key returns 422 MISSING_IDEMPOTENCY_KEY.

Endpoints that require the header

POST /v1/pix/charges     — Create a Pix charge
POST /v1/pix/transfers   — Initiate a Pix Out transfer

GET and DELETE requests and the authentication POST endpoints can omit this header.