Idempotency
Retry send requests safely without sending a message twice.
Networks fail: a send request can time out after the API has already accepted it. To retry safely, give each message
an idempotencyKey, a string of up to 128 characters that is unique for that message in your system (an order id, an
event id, a UUID you store).
{
"channel": "email",
"recipients": [{ "type": "Email", "value": "jane@example.com" }],
"templateId": "0197a5f0-2b1c-7e44-8a55-1c2d3e4f5a6b",
"variables": { "orderId": "1042" },
"idempotencyKey": "order-1042-shipped"
}How it works
- The key is unique per project.
- If a message with the same key already exists, the API does not create a new one: it answers
202 Acceptedwith the existing message in its current state (which may already beCompleted). - The request body is not compared. A different body with an already used key still returns the original message, so never reuse a key for a different message.
- Keys are checked after request validation: an invalid request answers
400whatever its key. - You can find a message by its key with
searchon List messages (exact match).
Recommended retry pattern
- Generate the key once, before the first attempt, and store it with your own record.
- On a timeout, a network error or a
5xxresponse, retry with the same key, with exponential backoff. - Do not send the same new key from several threads at the same time; send it once and retry only after a failure.
- Do not retry
4xxresponses (except429, see Rate limits) without changing the request.
Messages sent without a key are never de-duplicated: each request creates a new message.