Idempotency
Sending a request twice without doing the thing twice: the Idempotency-Key header on a send, what a repeat answers, how each SDK, the command line and the MCP server pass the key, and which other writes are safe to repeat.
On this page
Why a key
A request can be handled and its answer lost on the way back. The program that sent it cannot tell that from a request that never arrived, and for most calls it does not matter: reading twice is harmless. Sending mail twice is not. An idempotency key is a name you give one intended send, so that the API can recognize the second attempt as the first one again.
One operation takes the Idempotency-Key header: POST /v1/inboxes/{inboxId}/send. Mail that has left cannot be taken back, so the send is the call that takes a key.
The header
Idempotency-Key is 1 to 255 printable ASCII characters (^[!-~]{1,255}$). The API remembers a key for 24 hours, for the inbox it was used on.
curl -s -X POST "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/send" \
-H "authorization: Bearer $DOORMAN_API_KEY" \
-H "idempotency-key: order-2847-reply" \
-H "content-type: application/json" \
-d '{
"threadId": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
"text": "Thanks, confirming for Thursday."
}'- The same key, the same request
- The original answer again, with the header
Idempotent-Replayed: true. Nothing is sent a second time. - The same key, a different request
422 idempotency_key_reused. A key names one send: a new send needs a new key.- The same key, while the first attempt is still running
409 idempotency_in_progress. Wait a moment and send again.- The same key, after the first attempt failed
- The send is tried again. A failed send releases its key, so the key can be used once the cause is fixed.
| Status | Error | Meaning |
|---|---|---|
| 422 | idempotency_key_reused | This Idempotency-Key was already used for a different request. |
| 409 | idempotency_in_progress | A request with this Idempotency-Key is still being processed. |
Choosing a key
- Derive the key from what the send is about: the order and the step, the thread and the turn, the event being answered. The same intention then gives the same key on every attempt, from every process.
- Do not derive it from the time or from a random number made at the moment of the attempt: a retry would make a new key and send again.
- Keys are kept apart by inbox. The same key on two inboxes is two sends.
- After 24 hours a key is forgotten, and the same key sends again. Something that may be retried later than that needs a record of its own that it was done.
The key on each surface
const sent = await client.inboxes.reply("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
{ text: "Thanks, confirming for Thursday." },
{ idempotencyKey: "order-2847-reply" },
);
if (sent.replayed) console.log("This reply had already been sent.");sent = client.inboxes.send(
"inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
{"threadId": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m", "text": "Thanks, confirming for Thursday."},
idempotency_key="order-2847-reply",
)doorman inboxes send inb_01jc4q7w9k2m5n8p3r6t1v4x7z --thread-id thr_01jc5a1b2c3d4e5f6g7h8j9k0m \
--text "Thanks, confirming for Thursday." --idempotency-key order-2847-reply{
"name": "inboxes_send",
"arguments": {
"inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
"threadId": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
"text": "Thanks, confirming for Thursday.",
"idempotencyKey": "order-2847-reply"
}
}- TypeScript SDK
sendandreplytake{ idempotencyKey }as their last argument. The answer carriesreplayed, true when the API answered an earlier send again.- Python SDK
sendtakesidempotency_key. The answer is the API's own JSON, without areplayedfield.- Command line
--idempotency-key.- MCP server
- The
idempotencyKeyinput ofinboxes_send. - Agent runtime
ctx.replyandctx.senduse the id of the event being handled as the key unless you give another, so a handler that runs twice for one event sends once. See Replies that do not loop.
The other direction: handling an event once
What the API sends you can arrive more than once too. A webhook delivery that is not acknowledged is retried, the stream replays on reconnect, and a poll can overlap both. Every event has an event_id that stays the same across all of them: record the id once the work for it is done, and skip an id you have recorded. Timeouts, retries and duplicates has the detail, and the agent runtime does it for you.
Writes that are safe to repeat anyway
Most writes other than a send need no key, because doing them twice leaves things as doing them once did: setting a value that is already set, deleting what is already gone. The contract marks them, and the MCP server passes the mark to a model as idempotentHint.

