IOSOR Learn

Handling HTTP 402 and 429 Status Codes in API Retry Logic

Master resilient API retry patterns for white-label prepaid CPaaS by treating HTTP 402 and 429 status codes with distinct ledger logic.

Handling HTTP 402 and 429 Status Codes in API Retry Logic.

Understanding Prepaid CPaaS HTTP Status Architecture

When building automated communication integrations, your software relies on predictable HTTP responses to maintain uptime. Unlike standard post-paid software where limits are elastic, a white-label prepaid CPaaS operates on a strict ledger balance and real-time funding model. Every API request—whether dispatching an OTP, streaming an SMS, or registering a webhook—triggers immediate authorization checks against your active wallet balance. Because funds must be available at the moment of execution, your architecture must handle financial state changes as strictly as network connectivity.

Anatomy of HTTP 402 Payment Required

An HTTP 402 status code indicates that the operation failed because your account balance is depleted or unable to cover the estimated MRC and usage costs. For instance, provisioning a phone number requires sufficient funds for the upfront allocation, matching our JIT + prepaid hold + assign for numbers workflow. If your balance drops below the USD 20 prepaid floor, the gateway rejects dispatch payloads immediately with a 402 error. Treating this as a transient network glitch is the trap; you must instead trigger a ledger top-up or alert your finance team.

Anatomy of HTTP 429 Too Many Requests

In contrast, an HTTP 429 response signals a rate-limiting event triggered by exceeding throughput thresholds, such as sending too many Verify OK requests per second. While a 402 error denotes a financial blockage, a 429 error is purely operational and temporary. When your system encounters a 429 status, the response headers typically include a Retry-After directive indicating how many seconds your worker should pause before dispatching the next payload. Implementing jittered backoff here prevents your workers from hammering the gateway during recovery windows.

Designing Smart Retry Policies and Circuit Breakers

Writing resilient client code requires separating error management into distinct branches based on the status code. For HTTP 429, implement a retry loop with randomized backoff and strict ceiling limits to recover gracefully. For HTTP 402, trip a circuit breaker that pauses outgoing traffic, triggers an automated ledger top-up or alerts an administrator, and waits for a webhook confirmation that funds have cleared. To maintain operational stability as your volume scales, never retry 402 errors without a state change.

Integrating Ledger Checks with Rate Limiting

To optimize system performance, combine pre-flight ledger balance checks with intelligent queue management. Before pushing bulk SMS campaigns or processing high-volume E.164 destination lists, query your account balance endpoint to ensure you clear the minimum operational threshold. Proper error classification also ties directly into broader platform health and transaction safety. For a deeper dive into these architectural patterns, review idempotency, retries, and money.

Start with IOSOR for Reliable CPaaS Infrastructure

Branch the client: HTTP 402 means the prepaid hold failed or the wallet cannot settle — stop the intent, surface top-up, do not retry. HTTP 429 means the rate window is full — honour Retry-After and resend the same Idempotency-Key. One handler that retries both codes will mint a second debit storm.

Related: API incident week: missing idempotency is a freeze, not a retry storm · Prepaid hold before first debit.

IOSOR takeaway

402 is a money stop; 429 is a pace pause. They are not the same retry.

Do: halt on 402 until a new hold can settle; back off 429 with the original key so prepaid sees one intent.

Don't: treat 402 as a soft 429, or hammer either code until 200 while the ledger is still deciding.

Was this guide helpful?

Related guides