idempotency_conflict

HTTP 409 Don’t retry REST and MCP

This Idempotency-Key has already been used for a different request body, so replaying it cannot return the original result and cannot safely create a new one either.

How to fix it

  1. Generate a fresh key for a genuinely new message. A key identifies one logical send, not one retry loop and not one session.
  2. Derive the key from the content, not from a counter. A UUID stored alongside the message you are about to send survives a process restart; an incrementing integer does not.
  3. Send the byte-identical body when retrying. Regenerating a timestamp inside the payload changes the hash and turns a safe retry into this conflict.
  4. Send the header on every send. A send without an Idempotency-Key is refused as invalid_request before it reaches the idempotency record at all.

Which rule fired

The idempotency record stores a SHA-256 of the canonical payload alongside the key digest. Claiming a key is an INSERT with ON CONFLICT DO NOTHING, so exactly one request wins the key; a request that loses the race then locks the existing row and compares payload hashes. Matching hashes replay the stored response snapshot. A mismatch is this error. The comparison is over the canonical payload, so a reordered recipient list or a whitespace difference that survives canonicalisation is a different payload as far as the check is concerned.

In error.messageMeans
Idempotency-Key was reused with different content. A send that is held for approval, or submitted as a draft, reuses an Idempotency-Key whose stored payload_sha256 differs from the hash of the current request.
Idempotency-Key was reused with a different payload. A direct send reuses an Idempotency-Key with a different payload, checked under a row lock taken on the existing idempotency record.

Why it works this way: Refusing is the safe branch. The alternative, treating a same-key different-payload request as a new send, is exactly how a retry turns into a duplicate email, and the whole reason the header exists is to make that impossible.

Example

POST /v1/projects/{project_id}/inboxes/{inbox_id}/messages → 409
{
  "error": {
    "code": "idempotency_conflict",
    "message": "Idempotency-Key was reused with a different payload.",
    "request_id": "req_8Kd2x91",
    "retryable": false,
    "details": {}
  }
}

Over MCP, send_message and create_draft return it as text in a result marked isError: true, not as this body.

Where it appears

  • POST /projects/{project_id}/inboxes/{inbox_id}/messages

Paths are relative to https://api.emailforagents.ai/v1.

View as Markdown

Search docs