---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://docs.sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.sendcorex.com/llms.txt"
---

Source: https://docs.sendcorex.com/idempotency

Guides

# Idempotency (safe retries)

Retry any send without sending the email twice. One key per email, reused on every retry.

- Idempotency-Key
- idempotency_key
- 24 h

## What it solves

Your request timed out. Was the email sent? Retry with the same key and you get the original result: nothing is sent twice.

## How to use it

Send the header `Idempotency-Key: <your key>` on `POST /v3.0/send`.

```
POST /v3.0/send
Authorization: <api_key>
Idempotency-Key: 3f1c9a52-6b1e-4f0e-9c2a-8d7e5b4a1f00
Content-Type: application/json
```

## Rules

Key format

1–255 characters: letters, numbers, `_ - : .` A UUID is perfect.

Valid for 24 hours

After 24 hours the same key counts as a new one.

One key per email

Reuse a key only to retry the exact same call.

Same key, different call

Same key with a different body or args returns `IDEMPOTENCY_KEY_REUSED` (422 on `/v3.0/send`).

First call still running

Returns `IDEMPOTENCY_IN_PROGRESS` (409 with `Retry-After: 1` on `/v3.0/send`). Wait 1 second and retry.

Only successes are stored

If the call failed, a retry with the same key runs again for real.

How to spot a replay

Header `Idempotent-Replayed: true` on `/v3.0/send`, or `idempotent_replayed: true` in `data` on the webmail API.

## Code examples

Each example creates one key and keeps it on every retry, so a timeout never sends the email twice.

POST /v3.0/send

```
KEY=$(uuidgen)   # one key per email, reused on every retry

for attempt in 1 2 3 4 5; do
  status=$(curl -s -o response.json -w '%{http_code}' --max-time 15 \
    https://mail.sendcorex.com/v3.0/send \
    -H "Authorization: $SENDCOREX_API_KEY" \
    -H "Idempotency-Key: $KEY" \
    -H 'Content-Type: application/json' \
    -d '{"to":"user@example.com","from":"noreply@yourdomain.com","senderName":"My App","subject":"Your receipt","body":"<p>Thanks for your order.</p>"}')

  case "$status" in
    000|409|429|5*) sleep $((2 ** (attempt - 1))) ;;   # timeout or busy: retry with the SAME key
    *) break ;;
  esac
done

cat response.json
```

## For AI agents

Always send an idempotency key. If a call times out, retry with the same key. The email is never sent twice.

## Related errors

[`INVALID_IDEMPOTENCY_KEY`](https://docs.sendcorex.com/errors#invalid_idempotency_key) [`IDEMPOTENCY_KEY_REUSED`](https://docs.sendcorex.com/errors#idempotency_key_reused) [`IDEMPOTENCY_IN_PROGRESS`](https://docs.sendcorex.com/errors#idempotency_in_progress) [`IDEMPOTENCY_REPLAY_FAILED`](https://docs.sendcorex.com/errors#idempotency_replay_failed)
