Skip to content

Idempotency

A network timeout leaves you unsure whether a send went through. Retrying might send it twice. An idempotency key makes the retry safe.

Send an Idempotency-Key header with POST /v1/emails or POST /v1/emails/batch. Use a value that identifies the message in your system, such as receipt-1042:

Terminal window
curl https://api.duta.indra.sh/v1/emails \
-H "Authorization: Bearer $DUTA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: receipt-1042" \
-d '{ "from": "Kedai <resit@kedai.my>", "to": "siti@example.com", "subject": "Resit #1042", "text": "Terima kasih." }'
  • A key is 1 to 256 printable characters, scoped to your account and remembered for 24 hours.
  • A repeat with the same body does not send again. It returns the first response with the header Idempotent-Replayed: true.
  • A repeat with a different body or path is refused with 409 idempotency_conflict. A key names one message.
  • A repeat while the first is still running is also refused with 409. Wait and retry.

With the Resend SDK, pass { idempotencyKey: 'receipt-1042' } as the second argument to emails.send.