# Idempotency keys: retry without double-sending

An idempotency key makes a send safe to retry. Send the same Idempotency-Key with the same request and bubbl3 returns the first answer instead of sending again; send it with a different request and bubbl3 refuses it with 409. Name each key after what you're doing once, such as an order's confirmation, and keys last 24 hours.

## The short version

1. **Name the action** Build the key from what you're doing once, such as order-1042-confirmation.
2. **Send it on every write** Pass the key in the Idempotency-Key header, or the SDK's idempotencyKey option.
3. **Retry with the same key** After a network error, a 429 or a 5xx, retry with the same key and the same request.
4. **Handle a conflict** On 409 idempotency\_conflict, read the current state or wait for the first request to finish.

Networks fail at the worst moment: after your request reached the server, but before the answer reached you. Did the text go out? Without an idempotency key, retrying might send it twice.

## What idempotency is

A request is idempotent when making it twice has the same effect as making it once. Reading a message is idempotent; sending one isn't, unless the server can tell a retry from a new request.

An IETF draft, now expired, describes an `Idempotency-Key` request header for exactly this: making methods such as POST and PATCH fault-tolerant. bubbl3 uses the same header name on every write call.

## How bubbl3 fingerprints a request

bubbl3 keeps each key, for your workspace, with the request it came with and the answer it gave:

- The same key with the same request returns the first answer, with `idempotent-replayed: true`. Nothing is sent again.
- The same key with a different request is refused with `409 idempotency_conflict`, and so is a retry while the first request is still running.
- Keys last 24 hours. They're 1 to 255 printable characters without spaces.
- A `5xx` answer frees the key, so a retry runs the request again. A `4xx` answer is kept, so a retry gets the same answer.
- Keys starting with `outreach:`, `workflow:` or `agent:` are reserved for messages bubbl3 sends itself, and are refused.

```bash
curl https://api.bubbl3.com/v1/messages \
  -H "Authorization: Bearer $BUBBL3_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-confirmation" \
  -d '{ "to": "+13475550142", "body": "Your order is on its way." }'
```

The MCP server's `send_message` and `reply_to_conversation` tools take an `idempotency_key` that works the same way.

## Patterns

- **Name the action, not the attempt.** `order-1042-confirmation` is a good key. A random value made fresh on each retry protects nothing.
- **One key per message you mean to send.** A reminder 48 hours ahead and one on the day are two messages: `appt-881-reminder-48h` and `appt-881-reminder-day`.
- **Retry with backoff, with the same key.** After a network error, a `429` or a `5xx`, wait and retry. For a `429`, wait for `retry-after`.
- **Let the SDK help, but pass your own key.** The [TypeScript SDK](/developers/sdk) makes a key per call if you don't, which protects its own retries but not yours. Pass `{ idempotencyKey }` on every send.
- **Webhooks that trigger sends.** If a webhook from another system triggers a text, build the key from that system's event id, so a retried webhook can't text twice.

See the [idempotency key](/glossary/idempotency-key) glossary entry and the [TypeScript quick-start](/guides/imessage-api-quickstart-typescript).

## Keep reading

- [Idempotency key](https://bubbl3.com/glossary/idempotency-key)
- [TypeScript SDK](https://bubbl3.com/developers/sdk)
- [Send your first iMessage with TypeScript](https://bubbl3.com/guides/imessage-api-quickstart-typescript)

Updated: 2026-10-17

## Sources

- [The Idempotency-Key HTTP Header Field](https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/), IETF, checked 2026-10-17
