Idempotency
Networks fail at the worst moments: you POST a send, the connection drops, and now you don't know whether the email went out. Idempotency lets you retry that request safely. Send the same Idempotency-Key header again and Bird replays the original response instead of processing the request a second time.
How it works
Idempotency is opt-in. Add an Idempotency-Key header to any POST, PATCH, or DELETE request; requests without the header are processed normally with no deduplication. GET requests are naturally idempotent and ignore the header.
The SDKs send a key on every mutating request already; each one also lets you set your own, which is what these tabs show.
await bird.email.send(
{
from: "hello@yourdomain.com",
to: ["delivered@messagebird.dev"],
subject: "Welcome!",
html: "<p>Thanks for signing up.</p>",
},
{ idempotencyKey: "welcome-user/usr_abc123" },
);client.email.send(
from_="hello@yourdomain.com",
to=["delivered@messagebird.dev"],
subject="Welcome!",
html="<p>Thanks for signing up.</p>",
options={"idempotency_key": "welcome-user/usr_abc123"},
)_, err := client.Email.Send(context.Background(), bird.EmailSendParams{
From: "hello@yourdomain.com",
To: []string{"delivered@messagebird.dev"},
Subject: "Welcome!",
HTML: "<p>Thanks for signing up.</p>",
}, option.WithIdempotencyKey("welcome-user/usr_abc123"))$bird->email->send(
from: 'hello@yourdomain.com',
to: ['delivered@messagebird.dev'],
subject: 'Welcome!',
html: '<p>Thanks for signing up.</p>',
options: new RequestOptions(idempotencyKey: 'welcome-user/usr_abc123'),
);curl -X POST https://us1.platform.bird.com/v1/email/messages \
-H "Authorization: Bearer $BIRD_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: welcome-user/usr_abc123" \
-d '{
"from": "hello@yourdomain.com",
"to": ["delivered@messagebird.dev"],
"subject": "Welcome!",
"html": "<p>Thanks for signing up.</p>"
}'A key is any non-empty string up to 255 characters. The recommended format is a deterministic key derived from your own entities, <event-type>/<entity-id> (for example welcome-user/usr_abc123), so retries across process restarts share a key; a random UUID per logical operation works too. The Bird SDKs generate a UUID key automatically for every mutating request and reuse it across their internal retries, so SDK users get safe retries without doing anything.
Keys are scoped to your workspace (to your organization on organization-level endpoints), so two workspaces can use the same key string without colliding. A completed response is kept for 3 hours; a retry after that window is processed as a fresh request. The window covers typical retry schedules. No deduplication record remains after it expires.
Replays
When Bird sees a key it has already completed, it returns the cached response, same status code, same body, without re-running the request. Replayed responses carry one extra header so you can tell them apart from fresh processing:
Code example
HTTP/1.1 202 Accepted
Idempotency-Replay: trueSuccessful responses are what replay protects: the case where your first attempt worked but you never saw the answer. Requests that fail don't burn the key. A validation or business-rule rejection releases it, so a corrected retry under the same key is processed fresh rather than replaying the old error.
Failure modes
| Scenario | Response |
|---|---|
| Same key, same request, original completed | Cached response replayed with Idempotency-Replay: true |
| Same key, different request body or endpoint | 409, E01005 IdempotencyKeyReuse |
| Same key, original request still in flight | 409, E01004 RequestInProgress |
| Key longer than 255 characters | 400, E01002 InvalidRequest |
Reusing a completed key with a different request is treated as a client bug: Bird returns 409 immediately rather than silently handing you a response that doesn't match what you sent. Generate a new key for the new request. The comparison covers the method, endpoint, path and query parameters, and the raw request body, so even a whitespace change in the body counts as a different request.
RequestInProgress means a concurrent request with the same key hasn't finished yet, typically an aggressive client-side timeout retrying while the first attempt is still processing. The in-flight lock expires within 30 seconds, so wait briefly and retry. See Errors for the envelope these come wrapped in.
What's not cached
5xx responses are never cached. A server error means Bird doesn't know whether the request took effect, and caching it would permanently block a successful retry. Instead, the key unlocks and Bird processes your retry as a new attempt. Retry 5xx responses and timeouts with the same key. You then receive the original successful response if the first attempt completed, or the response from the new attempt.
Deduplication protects against duplicate side effects and does not control throughput. If its store is briefly unavailable, requests proceed without deduplication. Design your keys so your system can tolerate a rare duplicate.
Practical guidance
- Generate one key per logical operation and reuse it for every HTTP attempt of that operation.
- Retry on network errors, timeouts, and 5xx with exponential backoff, reusing the same key each time.
- Treat 409 IdempotencyKeyReuse as a bug in your key generation. Do not retry it.
- Skip keys on GET requests and on operations that are naturally idempotent in your domain; the mechanism is there for the cases where a duplicate would hurt.
Next steps
- Idempotency API reference: header and response-header schemas
- SDK concepts: automatic key generation and retry behavior in the SDKs
- Errors: the error envelope and code catalog
- Sending email: send and batch endpoints