Choose a stable key
Generate one unique key for each logical email. A business identifier is often better than a random value because it survives job and process restarts.
Idempotency-Key: order-1048-receipt-v1
Good keys identify a single intent: user-42-password-reset-1700000000, invoice-2026-1048, or a persisted UUID created with the application record.
Retry the identical body
Emailyt binds the key to a SHA-256 hash of the JSON request. Reuse the same key only with the same serialized body.
202
The first request was accepted and queued.
200
The key already completed; the original message ID is returned with
duplicate: true.409
idempotency_in_progress: another request owns the active claim. Retry shortly.409
idempotency_conflict: the key was reused with a different body. Stop and investigate.Recommended retry loop
- Persist the idempotency key before making the API request.
- Use a finite client timeout, such as 10 seconds.
- Retry connection failures,
409 idempotency_in_progress,429, and5xxresponses with exponential backoff and jitter. - Do not retry validation, authentication, sender, suppression, or idempotency-conflict errors without changing the underlying request.
- Persist the returned message ID and stop retrying.
Never generate a new key during a retry. A new value represents a new logical send and can produce a duplicate email.
Example backoff
const retryable = new Set([409, 429, 500, 502, 503, 504]);
for (let attempt = 0; attempt < 5; attempt++) {
const response = await sendWithStableKey();
if (response.ok) return response.json();
const body = await response.json();
if (!retryable.has(response.status) ||
body.error?.code === "idempotency_conflict") throw body;
await new Promise(r => setTimeout(r, (2 ** attempt * 250) + Math.random() * 200));
}