Retries and idempotency
Retry safely: a repeated request never sends twice.
Send an Idempotency-Key header (any unique string, such as your order id plus the email's purpose) and retry freely: a repeat of the same request within 24 hours returns the first answer (with Idempotent-Replayed: true) and sends nothing twice.
curl -X POST https://yousendit.io/api/v1/emails \
-H "Authorization: Bearer $YOUSENDIT_API_KEY" \
-H "Idempotency-Key: order-1042-receipt" \
-H "Content-Type: application/json" \
-d '{ … }'The same request
"The same request" means the same bytes: the same key with a different body, even the same JSON formatted differently, is refused with 409 idempotency_key_reused. Kept under the key: the answer once the request was read and judged, including a 400 about the email itself, a 404 and a 409. Not kept, so a corrected retry goes through: a request that could not be read (malformed JSON, an unknown field, a wrong type, a body over the limit), and a 403, 422 or 429.
When to retry
Retry on 429 (after Retry-After) and on 5xx. Do not retry other 4xx answers unchanged.