Your retry wrapper fired at 02:14 because the request timed out, and the customer now has three password-reset emails. Or one. Nobody on the team can say which, because the only record of the first attempt is a timeout in your logs. Two questions follow, and they are different: did the message get accepted, and will the retry produce a second one? An idempotency key on an email API answers the first, if you store what it returns. It cannot answer the second on its own, and four of the failures that produce a duplicate are ones it cannot see at all.
What an idempotency key actually guarantees
Idempotent, in the HTTP sense, means a repeat of the same call leaves the system where the first call left it [1]. HTTP treats GET, PUT and DELETE that way by definition and POST as not idempotent, which RFC 9110 §9.2.2 covers [2]. Sending email is a POST, which is why the header exists: Idempotency-Key is specified in an Internet-Draft in the IETF HTTPAPI working group, still in progress, and it is not a standard [1].
The contract is narrower than the name suggests. The provider stores the key alongside the request it arrived with, and a second request carrying the same key and the same content produces one effect rather than two [3]. Transmitly scopes the key to the workspace, so two workspaces can use the same string without colliding [3]. The promise is the provider's, about requests that reach it, and it stops at that boundary. Transmitly's idempotency section of the API docs states the scope, the replay behaviour and the conflict response.
The key is scoped to a request, not to a message
A key identifies a request you made. A message is what the platform accepted and then tried to deliver. The header governs only the first. Dochia's post is explicit that a key identifies a claimed operation and does not define request equivalence, replay policy or downstream deduplication [4]. It also says requests carrying different keys are distinct requests and are each processed, even when their fingerprints match [1]. One message can come from one request; it can equally come from two requests with two different keys.
Same key, same request, one effect
"Same request" means the key plus a fingerprint of the content. A resource that does not compute a fingerprint cannot detect a key reused with a different payload at all, and handles the request as a duplicate [1]. Where a fingerprint is computed, a mismatch fails the request instead of returning the original result [1]. That is the edge of the guarantee: recognition depends on the content matching.
What it prevents
Three cases the header was designed for.
A retry after a timeout where the first request did land. The docs treat an ambiguous failure as a reason to send the same key again, not to declare the send dead. A retry then either hands back the message id the first attempt produced, or — if nothing was committed — takes the message for the first time [3].
A double submit from a UI. Two clicks produce two requests with the same key and body, and the second returns the first response with no new delivery work queued [3].
A queue redelivering the same job. Trigger.dev's docs list deduplicating webhook processing as a use case: the handler runs once per event even when the event arrives more than once [5].
What it does not prevent
| Failure mode | What the key does | What you need instead |
|---|---|---|
| Retry generates a new key each attempt | Nothing. Two keys, two requests, two messages. | Derive the key from the business event, not from the attempt. |
| Same key, different content | Refuses the second request, or replays the first response. Either way the second message is not created. | An explicit conflict policy, and a log line when it fires. |
| Retry after the retention window | Nothing. The key is gone, so the request looks new. | A window longer than your longest retry tail, and to know what it is. |
| Two code paths, two keys, one message | Nothing. The key is per caller, not per intent. | One owner per message: a single send function, not three. |
| Duplicate after acceptance | Nothing. The message was already accepted; the duplicate is downstream. | Idempotent event handling keyed on the message id or attempt id. |
Row 2 is a per-provider contract, not a rule you can infer from the header. Transmitly returns 409 idempotency_conflict when a key is reused with a different body, including a changed recipient, subject, body or tag [3]. Stripe compares incoming parameters to the original and errors when they differ, surfaced as idempotency_error [6] and a 409 Conflict [6]. The Internet-Draft recommends 422 for a different payload and reserves 409 for a retry arriving while the original is still processing [1], which matches neither provider.
Row 3 has no universal answer either. Stripe documents that, for API v1, keys can be removed automatically once they are at least 24 hours old, and that a key reused after pruning generates a new request [7]. That is a capability and a floor, not a fixed window, and it is scoped to v1. Transmitly's docs state no retention window; they say keys are not recycled automatically, which is not a period [3]. The draft asks the resource to define its expiry policy and publish it [1].
Row 1 is the one that looks like it is working. Two attempts, two keys, and the provider has no reason to connect them, so it creates two messages. The docs point at the business event as the source of the value, and warn that minting a fresh one inside the retry loop is self-defeating: the second attempt arrives under a different key, so the platform cannot connect it to the first [3].
Row 5 is the one the header cannot reach, and the failure its name hides. The key's job ends at acceptance. POST /v1/emails returns 202 only after the message, its per-recipient deliveries, the key and the outbox event commit in one transaction [8]. Acceptance is not a delivery attempt [9]. Delivery is a later and separate state: delivered_to_mx means a remote mail exchanger returned 2xx for that recipient, evidenced by smtp_code, enhanced_code, mx_host and delivered_at [9]. The duplicate lives downstream of both. Webhook retries use exponential backoff, are dead-lettered after eight attempts, and carry event ids that are stable across retries, so receivers deduplicate on id [10]. Transmitly's own idempotency page says ambiguous failures on other transports can still produce duplicates and that receivers should be idempotent as well [3]. Trigger.dev states the same limit from the other side: a key stops a task being triggered twice, and does not stop the code inside that task running twice [5]. Exactly-once delivery is not the same thing as exactly-once business effect [4]. The distinction is the one behind what a 202 Accepted means: the platform owns the message, and anything that reads the event twice can still produce a second one.
One boundary worth naming: SMTP has no idempotency key at all. Transmitly's docs say SMTP cannot guarantee exactly-once acceptance, that a Message-ID is preserved when present, and that a client retrying after a timeout can create a duplicate [3]. A reader sending over SMTP is outside this guarantee entirely.
The key is more useful as a lookup handle
A stored key answers a question after the request is gone: did this already happen, and what happened to it? It is answerable only if the key and the response were kept together.
Derive the key from the business event
Build the key from the event that caused the send, not from the attempt. The docs name the order id and the password-reset token as examples, and note that where one event legitimately produces several messages you add a stable suffix such as order-1042-receipt and order-1042-copy [3]. The request shape is documented at POST /v1/emails.
The Internet-Draft recommends a UUID or similar random identifier [1], which reads against that advice until the two claims are separated. Random is fine as a value. It is wrong as a per-attempt value. A UUID generated once, when the business event is created, and stored with it, satisfies both: unguessable, and identical on every retry.
// Generated once with the business event, stored on it.
// A retry reads it back; it never generates a new one.
const key = `reset-${resetTokenId}`;
async function sendReset(key: string, to: string) {
const res = await fetch(`${API_BASE}/v1/emails`, {
method: "POST",
headers: { ...authHeaders, "Content-Type": "application/json", "Idempotency-Key": key },
body: JSON.stringify({
from: "[email protected]", to,
subject: "Reset your password",
text: "Use this link within 30 minutes: https://example.com/reset/…",
stream: "transactional", tags: ["password-reset"],
}),
});
if (!res.ok) throw new Error(`send failed: ${res.status}`);
return res.json(); // { id: "msg_2f9c…", status: "accepted", recipients: 1 }
}
// Same key, same body: the retry cannot create a second message.
for (let attempt = 0; attempt < 3; attempt++) {
try { return await sendReset(key, to); } catch { await sleep(2 ** attempt * 500); }
}
Retry 429 and 5xx with jitter and the same key; do not retry a 4xx validation error unchanged [11].
Store the outcome next to the key
Keep four things: the key, the message id the platform returned, when it was accepted, and the per-attempt outcome. Transmitly records SMTP code, enhanced code, MX host and reason for every attempt, which is what per-attempt records means in practice [12].
Once the message exists, the message id matters more than the key. The key answers did I ask. The message id answers what happened, and it is the handle for state: GET /v1/emails/{id} or GET /v1/messages/{id}/deliveries [8].
Keep accepted and delivered to MX separate in that record. Accepted is a 202 and a message id [9]. Delivered to MX is a 2xx from the recipient's mail exchanger, with its own evidence fields [9]. One status column collapses the two and cannot answer the next question.
A checklist before you ship
- Derive the key from the business event and store it on that event, so a retry reconstructs it.
- Read your provider's conflict policy, and log the error when it fires.
- Find out your provider's retention window, or that it documents none, and compare it to your longest retry tail.
- Put one function in charge of sending each kind of message.
- Deduplicate webhook events on the event id, and make the handler safe to run twice.
- Store the message id and the per-attempt outcome next to the key.
A key makes a request safe to repeat. It does not make a message safe to repeat, and the space between those two sentences is where duplicate email lives [8] [9] [3].
Sources
- The Idempotency-Key HTTP Header Field (editor's copy, current revision) — IETF HTTPAPI Working Group, 2026-11-21
- RFC 9110: HTTP Semantics (plain-text table of contents) — RFC Editor / IETF, 2022-06-24
- Idempotency Keys for Safe Retries | Transmitly Docs — Transmitly, 2026-11-20
- Idempotency Is Easy Until the Second Request Is Different (scope of the key) — Dochia CLI Blog, 2026-05-07
- Idempotency - Trigger.dev docs (SERP rank 10) — Trigger.dev, 2026-11-12
- Errors | Stripe API reference — Stripe, 2025-06-09
- Idempotent requests | Stripe API reference — Stripe, 2025-06-09
- Send Email API: POST /v1/emails | Transmitly Docs — Transmitly
- Email Delivery States, Defined | Transmitly — Transmitly
- Email Webhooks: Events, Signatures & Retries | Transmitly Docs — Transmitly
- Email API Error Codes & Retries | Transmitly Docs (retry guidance) — Transmitly, 2026-11-20
- Email Delivery Infrastructure & SMTP Observability | Transmitly — Transmitly
This article was researched, written and edited by AI under human supervision, and checked against Rankwrite's public editorial rubric.