WhatsApp Cloud API rate limits, error 131047 and the 24-hour window
Two separate things block a send: rate limits (you are sending too fast) and the customer service window (you are not allowed to send a free-form message right now).
Rate limits in the Cloud API
Section titled “Rate limits in the Cloud API”Meta’s throughput page states that each registered business phone number supports 80 messages per second by default, with an automatic upgrade to 1,000 messages per second for eligible numbers. Throughput counts inbound and outbound messages. When you exceed it, the API returns error 130429 until you are back within the limit.
The error codes page lists related throttling errors:
130429: Cloud API message throughput reached.131056: too many messages from your number to the same recipient in a short period. You can still send to other numbers.80007: the WhatsApp Business Account reached its rate limit.131048: sending is restricted because of quality or spam signals.
The 24-hour customer service window
Section titled “The 24-hour customer service window”When a user messages or calls you, a 24-hour customer service window opens. Each new message or call from the user resets it to 24 hours. While it is open you can send any service message. After it closes you can only send approved template messages.
If you send a free-form message with the window closed, the API returns error 131047, described in the error table as more than 24 hours since the recipient last replied. Meta’s remedy is to send a template message instead.
How the SDK behaves
Section titled “How the SDK behaves”Reads and non-message requests retry on HTTP 429, any 5xx, and network or timeout failures. Message sends (POST to /messages) retry on 429 only, because a retry after a lost response could deliver the message twice; set retryMessageSends: true to retry them on 5xx and network failures too. Defaults are maxRetries: 2 (three attempts in total) and a 30-second timeout per attempt. When the response has a Retry-After header, the SDK waits that long. Otherwise it waits with exponential backoff and jitter, starting at 300 ms and doubling per attempt. Multipart uploads are never retried.
The error classes help you branch:
WhatsAppRateLimitErroris thrown for HTTP 429 and for the codes130429,131056and133016. ItsretryAfterMsis set when the server sentRetry-After. The SDK retries only on the HTTP status, so a rate limit code returned with a status other than 429 (or 5xx, where retries apply) reaches you without a retry.WhatsAppReEngagementErroris thrown for code131047.
// Defaults: timeoutMs 30000 per attempt, maxRetries 2 (so up to 3 attempts).const client = new WhatsAppClient({ accessToken: process.env.WHATSAPP_ACCESS_TOKEN!, phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!, maxRetries: 3,});try { await client.messages.sendText('15551234567', 'Your order has shipped.');} catch (error) { if (error instanceof WhatsAppReEngagementError) { // Code 131047: more than 24 hours since the user last replied. // Send an approved template instead. await client.messages.sendTemplate('15551234567', { name: 'order_update', language: { code: 'en_US' }, }); } else if (error instanceof WhatsAppRateLimitError) { // Retries are already exhausted when this reaches you. console.warn(error.code, error.retryAfterMs); } else { throw error; }}WhatsAppErrorCode has named constants for the codes the SDK maps:
// Compare against a named constant instead of a number.const reEngagement: number = WhatsAppErrorCode.RE_ENGAGEMENT_MESSAGE; // 131047const throughput: number = WhatsAppErrorCode.RATE_LIMIT_HIT; // 130429The SDK does not track the window or throttle for you. Record the time of each inbound message if you need to decide between a free-form message and a template before sending. See Errors and retries for the full hierarchy and Send a template message for the fallback.
Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.