To cap SMS spend per tenant, count segments (not messages) against a per-tenant budget, reserve that budget atomically before every send, and settle it when the text goes out. Put a soft limit in front of the hard one so the customer hears from you before a send is refused.
We make Ready, and the platforms we talk to all hit this the same way: one customer's runaway automation burns a month of budget in an afternoon. This guide is the design we'd build, not a feature list of any API. Ready doesn't ship a spend-cap endpoint, so the enforcement lives in your platform, in front of POST /v1/messages.
What you're actually capping
There are two different limits, and mixing them up causes most of the bugs.
- A spend cap protects money: yours, if you rebill later, or the customer's, if they prepaid.
- A volume quota protects reputation and fairness: how many segments a tenant can push per day, regardless of balance.
A tenant can be well under budget and still over quota. Keep both as separate counters with separate error codes so support can tell which one fired.
Count segments, not messages
Carriers meter segments. A single SMS segment holds 160 GSM-7 characters, or 153 once a message splits into multiple parts. One emoji drops the limit to 70 (67 multipart). So a 140-character text with one emoji is 3 segments, not 1.
If your counter increments by one per API call, a tenant who adds an emoji to a template triples their real usage without moving your dashboard. Estimate segments before the send, using the same rules, and count that. Replies count too: an inbound text is billed like a sent one, so a cap that ignores inbound traffic will undercount a busy tenant.
The counters to keep
Keep these per tenant (per sub-account, if you model customers that way):
| Counter | Resets | Protects against |
|---|---|---|
spent | Each billing period | Overspend |
reserved | Never; settled continuously | Races between concurrent sends |
segments_today | Local midnight | Volume spikes |
segments_this_month | Monthly | Plan overage |
The reserved counter is the one people skip. Without it, ten workers all read "$4 left", all pass the check, and all send.
Reserve, send, settle
Make the check and the increment one atomic step. In Postgres, a single conditional update does it:
UPDATE tenant_budgets
SET reserved = reserved + $2
WHERE tenant_id = $1
AND spent + reserved + $2 <= hard_limit
RETURNING spent, reserved, soft_limit; Zero rows back means the cap is hit: refuse the job before it touches the API. One row back means you hold the budget, so send. Then settle: move the estimate from reserved to spent at the actual segment count once the send is accepted, or release it if the send fails.
A text that Ready holds and sends later is charged only when it sends, so settle on the send, not on acceptance of a held request. If you retry a failed call, reuse the same Idempotency-Key so a retry can't send twice, and tie the reservation to that key so a retry can't reserve twice either. Our post on deterministic idempotency keys for SMS covers how to derive them.
Soft limits, hard limits, and what each does
| Threshold | Suggested behaviour | Who's told |
|---|---|---|
| 50% of budget | Log only | Nobody |
| 80% (soft) | Keep sending, notify | Customer admin, your CS team |
| 100% (hard) | Refuse new sends, return a clear error | Customer admin, immediately |
| Hard plus grace | Optional small overage window for transactional traffic | Your finance team |
Those percentages are starting points, not benchmarks. Tune them to how fast your tenants actually burn budget.
One design choice matters more than the numbers: decide whether the hard limit blocks everything or only marketing traffic. Password codes and appointment reminders are usually worth letting through a small grace amount. Campaign texts aren't. Tag each send with a traffic class and give each class its own rule.
A prepaid wallet per sub-account
If your customers prepay, the wallet is the cap. Keep one balance per sub-account in your own ledger and treat it as a hard limit with a floor at zero. Ready bills on prepaid credits itself, so a wallet on your side maps cleanly onto how the upstream cost arrives.
Rules that keep a wallet honest:
- Write ledger rows (top-up, reserve, settle, refund), never edit a balance in place.
- Top-ups credit only after payment clears.
- Auto-recharge is a separate opt-in with its own monthly ceiling, so a bug can't drain a card.
- Show the customer the balance in segments as well as money, since segments are what they control.
For the billing side, see metering SMS usage per customer in your SaaS and the comparison of wallet rebilling and sub-account billing.
Alerts that people act on
Alerts fail by being noisy or late. Three that earn their keep:
- Threshold crossed: once per period per threshold, never repeated on every send.
- Burn-rate spike: projected exhaustion within a few hours at the current rate. This catches the runaway automation before the hard limit does.
- Refusal digest: one summary of refused sends per tenant per day, so a hard-limit hit doesn't generate a thousand emails.
Send alerts through a channel you control, and log every refusal with the tenant, the counter that fired and the traffic class. Our guide to SaaS usage-based billing alerts for SMS goes deeper on thresholds.
A worked example
This is an example with assumed numbers, not a measurement. A tenant has a monthly budget of 20,000 segments, a soft limit at 80% (16,000) and a daily quota of 2,000.
On day 9 they've used 15,000 segments. A workflow bug starts texting a 175-character message with an emoji to 3,000 contacts. That's 3 unicode segments per recipient, so the job is worth 9,000 segments.
With caps in place, the soft limit fires after about 333 recipients, when the month crosses 16,000, and the customer's admin is told that day. The daily quota of 2,000 then refuses the job after 666 recipients (1,998 segments), so the month ends near 17,000. Without the daily quota, the hard limit would have stopped it at 20,000, after 1,667 recipients. Without the segment estimate, the counter would have read one per text, and nobody would have noticed until the invoice.
FAQ
Should the cap live in my app or in the API provider? In your app. You know your plans, tenants and traffic classes. Treat any provider limit as a backstop, and keep your own counters as the source of truth.
What happens to a refused send? Return a distinct error to the caller, record the refusal, and never queue it silently. A silent queue turns a cap into a surprise bill later.
Do quiet hours interact with caps? Separately. A 409 QUIET_HOURS_BLOCK from the API is a time rule, not a budget problem, so release the reservation and handle it as a reschedule. See handling the quiet hours 409.
Next step
Start with one atomic reserve step and segment-based counters. Soft limits, alerts and wallets all sit on top of that. When you're ready to wire the send itself, the messages API docs show the request shape, and you can create an account to test it.