Skip to content

Idempotency and retries ​

Networks fail: a request may time out after the message was already accepted. To retry without sending the message twice, give POST /v1/messages an Idempotency-Key header.

bash
curl -X POST https://api.ace-send.com/v1/messages \
  -H "Authorization: Bearer $ACE_SEND_API_KEY" \
  -H "Idempotency-Key: deposit-88123-confirmation" \
  -H "Content-Type: application/json" \
  -d '{"to": "+5521998120937", "template": "deposit_ok", "language": "pt"}'

How it works ​

  • The key is 1–64 printable ASCII characters (no spaces). Derive it from your own event — an order id, a deposit id plus the kind of message — rather than a random value per attempt.
  • A repeat with the same key and the same body within 24 hours answers the message of the first request: the same 202 and the same id, with the header Idempotent-Replayed: true. No second message is sent or charged.
  • The same key with another body: 409 idempotency_conflict.
  • A repeat while the first request is still running: 409 idempotency_in_progress — retry in a moment.
  • A refused request (4xx) is not remembered: fix it and send again with the same key.
  • Keys are shared by all keys of the account, test and live; a key used in one mode answers 409 idempotency_conflict in the other.

When to retry ​

AnswerRetry?
No answer, a timeout, a connection errorYes, with the same Idempotency-Key
429Yes, after the seconds of Retry-After
500, 502, 503, 504Yes, with backoff and the same Idempotency-Key
409 idempotency_in_progressYes, after a second or two
409 insufficient_fundsAfter a top-up
Other 4xxNo: fix the request first

Back off exponentially with jitter — for example 1, 2, 4, 8 seconds plus a random part — and stop after a few attempts or when the message is no longer relevant (a one-time code a minute later).

By code:

CodeRetry?
bad_requestAfter fixing the request
api_key_invalidAfter fixing the request
api_key_ip_deniedAfter fixing the request
account_suspendedNo
api_key_scopeAfter fixing the request
free_text_not_allowedAfter fixing the request
not_foundNo
template_not_foundAfter fixing the request
method_not_allowedAfter fixing the request
payload_too_largeAfter fixing the request
validation_failedAfter fixing the request
invalid_numberNo
recipient_stoppedNo
destination_unavailableNo
message_too_longAfter fixing the request
template_unavailableAfter fixing the request
insufficient_fundsYes, later
idempotency_conflictAfter fixing the request
idempotency_in_progressYes, later
too_many_requestsYes, later
daily_limit_reachedYes, later
server_errorYes, later
service_unavailableYes, later

ACE SEND API v1