Safe retries with Idempotency-Key
Networks fail. If a request times out you cannot tell whether the email was sent. Add an Idempotency-Key header and you can retry as often as you need: the email is sent once.
How it works
curl -X POST https://api.signally.cloud/v1/email \
-H "Authorization: Bearer $SIGNALLY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: receipt-INV-1042" \
-d '{ "from": "[email protected]", "to": ["[email protected]"], "subject": "Receipt INV-1042", "text": "Paid: KES 2,400" }'The header is optional and works on POST /v1/email and POST /v1/email/batch.
| You send | We return |
|---|---|
| A new key | The request runs normally. |
| The same key and the same request again | The original response (same message_id), with the header Idempotent-Replayed: true. Nothing is sent and no credits are used. |
| The same key while the first request is still running | 409 idempotency_in_progress. Wait a moment and retry. |
| The same key with a different body or endpoint | 422 idempotency_key_mismatch. Use a new key for a new email. |
| The same key after the first request failed with an error | The request runs again. Errors are not stored, so you can fix the problem (for example top up credits) and retry with the same key. |
Choosing keys
- Use something that identifies the email in your system:
receipt-INV-1042,password-reset-{token id},welcome-user-881. A random UUID created once per email also works, as long as you reuse it on retries. - Keys are 1 to 255 printable ASCII characters without spaces, and are case-sensitive.
- Keys belong to your account, across all of its API keys.
- Keys are kept for 24 hours. After that the same key can be used again.
When to retry
- Retry with the same key on network errors, timeouts,
409 idempotency_in_progress,429and5xx, with increasing waits (for example 1, 2, 4, 8 seconds). - Do not retry other
4xxerrors unchanged: fix the request first.
Batch requests
For /v1/email/batch, the key covers the whole batch. If at least one recipient was sent, the response (with its per-recipient results) is stored and replayed on retries; send any failed recipients again in a new request with a new key. If no recipient was sent (for example because the account ran out of credits), the key is released and the same request can be retried.
What it does not guarantee
An idempotency key prevents duplicate sends from your retries. It cannot make the receiving side deliver exactly once, and it does not apply to SMTP. A 202 response means we accepted the email; delivery shows up later as a delivered or bounced event.
Stuck? Email [email protected] with your account name and the message ID or error code.