Retry-Safe WhatsApp Sends: Idempotency Keys, 409s and Timeouts
A timeout on a WhatsApp send does not tell you whether the message went out. Here is how the Idempotency-Key header, 409 and 202 responses make a retry safe on Blueticks.
Daniel Roth7 min read

On this page
To retry a WhatsApp send safely, put an Idempotency-Key header on the first request and send the same key and the same body on every retry. Blueticks then runs the send at most once: a replay returns the original message instead of creating a second one. A timeout alone cannot tell you whether the first attempt went out, so without a key a retry can message your customer twice.
Checked against the /v1 send code on production and the Python SDK 4.1.0 on 2026-11-19.
Why is a retry on a WhatsApp send risky?
Because a failed request and a failed send are different things. Your client can time out while the message is already on its way to WhatsApp. If your code retries, the customer gets the same message twice.
Agents and background jobs do this a lot, because they retry by default. The fix is not "never retry." It is to make the retry recognisable, so the API can say "I already did that."
How do you add an idempotency key?
Add the Idempotency-Key header to the send call:
curl -X POST https://api.blueticks.co/v1/scheduled-messages/+15551234567 \
-H "Authorization: Bearer bt_live_YOUR_KEY_HERE" \
-H "Idempotency-Key: order-4471-shipped" \
-H "Content-Type: application/json" \
-d '{"type": "text", "text": "Your order has shipped."}'The rules, from the API code:
- Keys are 64 characters at most. Keep the key at or under that.
- They are scoped to your workspace, so two workspaces can use the same string without clashing.
- They are kept for 24 hours. After that the key is forgotten, and the same key would send again.
- Use one key per logical message, not per attempt. Build it from the business event, like an order id plus a step name. A random value generated inside the retry loop defeats the point.
What happens when you reuse a key?
| You send | You get |
|---|---|
| Same key, same body | The original response: same message id, no second message |
| Same key, different body | 409 Conflict: "Idempotency-Key already used for a different request" |
| Same key, different chat | 409 Conflict: "already used for a different chat" |
| Same key while the first attempt is still sending | 409 with code idempotency_in_flight and a Retry-After header |
A replay does not get its own status code. It returns the same status as the original send, so you spot one by the message id coming back the same. The "different body" rule catches a real bug: edit the text, reuse the key, and you get an error instead of a silently dropped message.
What does the 409 "in flight" error mean?
It means your earlier attempt may still be sending, and nothing new was sent. The error body looks like this:
{
"success": false,
"error": {
"code": "idempotency_in_flight",
"message": "An earlier attempt of this send is still in flight; nothing was sent. Retry the same request after it settles.",
"requestId": "..."
}
}Do not generate a new key. Wait for the number of seconds in the Retry-After header and send the same request again.
What if the send times out?
For a send-now request (no sendAt), Blueticks reserves your key before it asks WhatsApp to send. That reservation lets the API settle an unclear outcome on a retry instead of guessing:
- The first attempt may still be running. The retry gets the
409above. The hold lasts up to four minutes, longer than the time the sending side waits for WhatsApp. - The hold has ended. The API checks WhatsApp's own record for that exact send. If it is there, you get the original message back and nothing is re-sent.
- It is not there. The API sends once more, under the same internal id, so a second unclear outcome can be checked the same way. A copy WhatsApp itself failed counts as not there.
- The check itself fails. You get a
504and nothing is sent. Retry again later.
Separately, a REST send that WhatsApp has not confirmed after about 50 seconds returns 202 Accepted instead of waiting for the proxy to cut the connection. The body carries the message id and a statusUrl of the form /v1/scheduled-messages/{id}. Poll that. The status stays pending until the send is found, then moves to confirmed. A miss is never reported as failed, because not finding a message is not proof that it was not sent.
Do you need a key at all?
Use one. Sends without one have a safety net, though. If a send with no key ends in an unclear outcome, Blueticks remembers the chat and the exact body for 15 minutes. An identical request in that window is resumed the same way, and while the first may still be going out you get a 409 with code send_in_flight. A send that succeeds leaves no such record, so sending the same text to the same person on purpose later still goes out.
It also covers callers that cannot set a header. For your own code, the net is a backstop, not a plan: it only covers identical bodies, and only for 15 minutes.
How do you do this in Python?
The official Python SDK takes the key as an argument:
from blueticks import Blueticks
client = Blueticks() # reads BLUETICKS_API_KEY from the environment
msg = client.scheduled_messages.create(
"+15551234567",
type="text",
text="Your order has shipped.",
idempotency_key="order-4471-shipped",
)
print(msg.id, msg.status)The SDK retries up to twice by default, with backoff, on 429, 502, 503 and 504. A POST is retried on those statuses only when you pass an idempotency_key, which is the right behaviour: no key, no automatic status retry. Connection errors are retried either way, so pass a key on every send.
What should the retry rules be?
| What happened | Retry? |
|---|---|
| Connection error or timeout | Yes, with the same key and body |
429 | Yes, after Retry-After |
409 idempotency_in_flight or send_in_flight | Yes, after Retry-After, same request |
502, 503, 504 | Yes, same key and body, with backoff |
202 | No. Poll the statusUrl |
409 "different request" | No. Fix the bug: you changed the body under a used key |
400, 401, 403, 422 | No. The request itself is wrong |
Also read the message status afterwards, as in how to send a WhatsApp message from an API, or subscribe to delivery status webhooks so a failure reaches you. For a longer bot example, build a WhatsApp bot in Python shows the same ideas in context, and the agent guide covers why an agent needs them most.
FAQ
Does this stop WhatsApp from showing a message twice? No. It stops the API from creating the send twice. What WhatsApp does with a message after that is outside the API.
Is the secret field the same as an idempotency key?
No. The secret body field is a correlation tag. It does not prevent duplicate sends. Use the header.
Does it work for scheduled messages?
Yes. A key on a sendAt request means a replay returns the same scheduled message instead of queuing another. The in-flight hold described above applies to send-now requests.
Can I use one key for a whole campaign? No. A key covers one send. For bulk sends, use a campaign, which handles pacing and retries for you.
Want more WhatsApp recipes? Join the free WhatsApp Growth Recipes community.


