Skip to content

Engineering

4 min read

Idempotency keys, explained with a coffee order

Retry a request safely without paying twice. A short guide to idempotency on every write endpoint.

Settlement grid with the Swiss franc symbol in dots

You order a flat white at a busy counter, pay, and step aside. Ten minutes pass and nothing arrives. Did the barista hear you? Did the payment go through? If you order again, you might get two coffees and two charges. If you do not, you might get nothing at all.

Most cafes solve this with a ticket. Your order has a number, and if you come back to ask, the barista checks the number instead of making a new drink. That ticket is an idempotency key.

The problem with timeouts

If your request times out, you do not know whether it went through. An idempotency key lets you ask again safely.

A timeout tells you only that you did not get an answer. The request might have failed before it reached us, it might have been processed and the response lost on the way back, or it might still be running. From your side, those three cases look identical.

For most API calls, guessing wrong is harmless. For money it is not. Retrying a mint, a conversion or a payout without protection can move funds twice, and undoing a completed payment is slow for everyone involved.

How the key works

Every write endpoint on Nostro accepts an Idempotency-Key header. That includes POST /v1/mints, POST /v1/conversions and POST /v1/payouts. You choose the value, and it identifies one logical operation on your side.

Send the same key, get the same answer for 24 hours.

The first time we see a key, we process the request and store the response. If the same key arrives again within 24 hours, we do not process anything. We return the stored response, with the same status code and the same body, including the ID of the original conversion or payout. Your retry is a question, not a new order.

Keys are scoped to your API key and environment. A key used with an sk_test_ key in the sandbox never collides with the same value in production.

Choosing a good key

The key should change when the intent changes, and stay the same when it does not. A few habits make that easy:

  • Generate one key per operation, not per attempt. A random UUID created when you decide to pay a seller, then reused for every retry of that payment.

  • Store it before you send. Write the key to your database with the pending operation, so a crash between sending and receiving does not lose it.

  • Or derive it from your own records. An invoice ID combined with an attempt purpose, such as the invoice number followed by the word payout, works well when each invoice is paid once.

  • Never reuse a key for a different request. If the body changes, so should the key.

If you send a key we have already seen with a different body, we reject the request with an error rather than guess which version you meant. That protects you from a bug quietly turning one payment into another.

Retrying well

Idempotency makes retries safe. It does not decide when to retry. A sensible pattern for money movement looks like this:

  • Retry on timeouts, connection errors and server errors, with the same key each time.

  • Wait a little longer between attempts, for example one second, then two, then four, with some random jitter so many clients do not retry at once.

  • Do not retry validation errors. A request that failed because of a bad amount will fail again.

  • Stop after a fixed number of attempts and raise an alert, then check the status of the operation before trying anything else.

Our SDK applies these rules for you. After npm i @nostro/sdk, every write call generates a key automatically unless you pass your own, and reuses it across its built-in retries.

Idempotency and webhooks

Keys protect the requests you send. Events we send to you need the same care in the other direction. A webhook can be delivered more than once, so store each event ID and ignore one you have already handled. Between keys on the way out and event IDs on the way back, a retried request never moves money twice and a repeated event changes nothing on your side.

Back to the counter

The coffee analogy holds up well. Keep your ticket, show the same ticket when you ask again, and never use yesterday’s ticket for today’s order. Do that, and a slow network is an inconvenience rather than a double charge.

You can try all of this in the sandbox before going live. Examples in this post are illustrative. Nostro is a demo company, not a real issuer.

Nostro logo: four dotted corridors converging on a lit square core

Nostro

Stablecoin infrastructure for EUR, USD, GBP and CHF.

All rails live

NEW ARRIVAL · TIPLINE ↗

© 2026 Nostro Ltd. Demo company, illustrative data, not a real issuer.

More templates by Nova Studio

Nostro logo: four dotted corridors converging on a lit square core

Nostro

Stablecoin infrastructure for EUR, USD, GBP and CHF.

All rails live

NEW ARRIVAL · TIPLINE ↗

© 2026 Nostro Ltd. Demo company, illustrative data, not a real issuer.

More templates by Nova Studio

Nostro logo: four dotted corridors converging on a lit square core

Nostro

Stablecoin infrastructure for EUR, USD, GBP and CHF.

All rails live

NEW ARRIVAL · TIPLINE ↗

© 2026 Nostro Ltd. Demo company, illustrative data, not a real issuer.

More templates by Nova Studio

Create a free website with Framer, the website builder loved by startups, designers and agencies.