All guidesFor developers

Idempotency keys: retry without double-sending

The short answer

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.

5 min readUpdated

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.
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 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 entry and the TypeScript quick-start.

Sources

  1. The Idempotency-Key HTTP Header Field, IETF, checked

Ready to see your first blue bubble?

Tell us who you text and roughly how many people a month. We'll reply within one business day with a recommended setup.