DOCS Live

The basics

Retrying safely (idempotency)

Send every call that moves money with an Idempotency-Key, so a retry after a timeout never charges or pays twice.

Networks fail. A call can time out after KulPay did the work, and you cannot tell from your side. Idempotency makes retrying safe: you send a unique key with the call, and the same key again returns the first result instead of doing the work a second time.

Every call that moves money requires an Idempotency-Key header (charges, refunds, payouts, deposit intents and confirmations, bill payments, PSP transactions). Without it the call is refused with 400 idempotency_key_required.

Before you start

A way to generate a unique value per operation (a UUID is fine) and to keep it with the operation in your own records, so a retry after a crash uses the same key.

The flow at a glance

#WhoWhat happens
1Your systemCreates a key for the operation and stores it with the operation.
2Your systemSends the call with the key.
3Your systemOn a timeout or 5xx, sends exactly the same call with the same key.
4KulPayReturns the first result; nothing is done twice.

1. Send the key with the call

Your system.

POST /charges · API reference

Add Idempotency-Key: <your unique value> to the request. For charges, your payment_id in the body plays the same role: the same payment_id with the same request returns the same payment, for as long as the payment exists.

Request

{
  "payment_id": "ord-2026-10-22-000981",
  "money": {
    "amount": "100.00",
    "currency": "MZN"
  },
  "source": {
    "type": "mobile_wallet",
    "mobile_wallet": {
      "network": "mpesa",
      "phone_number": "+258840000001"
    }
  },
  "country": "MZ"
}

2. Retry with the same key

Your system, after a timeout, a dropped connection or a 5xx.

Send the identical request with the identical key. You get the original response. Never retry with a new key: that is a new operation.

The same key with a different request is 409 idempotency_key_reused: a key names one operation and its facts. Responses are replayed for 24 hours; after that, read the object back instead.

3. Recover a lost answer

Your system, when you lost the response and cannot retry.

GET /payments · API reference

Read the payment by your own payment_id (GET /payments?payment_id=…) instead of charging again. Other objects have their own reads by your reference: deposits by intent ID, transfers by partner_reference, PSP transactions by originator_reference.

Errors that matter here

Every error is application/problem+json with a stable code; branch on the code, not the message. The full list is in the error catalogue.

ErrorWhenWhat to do
400 idempotency_key_required

A call that moves money was sent without the header.

Send a unique key per operation.

409 idempotency_key_reused

The key was used before for a different request.

Use a new key for a new operation; reuse a key only to retry the same one.

409 idempotency_replay_unavailable

The repeated call's answer held a secret (a key, a token), which is never shown twice.

List the resources to find the one it made.

500 internal_error

Something failed on KulPay's side.

Retry with the same key; if it persists, contact support with the X-Request-ID.

Testing it

Send a test charge, then send it again with the same key: the same payment comes back. Change the amount and send it once more with that key: 409 idempotency_key_reused.


All flows · API reference · Error catalogue