New: every plan now includes free incoming texts and rollover credits. See pricing →
Search Help Center Documentation

Guide

Rate limits

Each API key can make up to 600 requests a minute. Every answer tells you where you stand.

How the limit works#

  • Up to 600 requests per minute, counted per API key. Two apps with their own keys do not use up each other's requests.
  • The minute starts with the first request and the count starts again when it ends.
  • It is meant to stop a runaway script, not to slow normal use. For bulk work use the bulk endpoints: POST /v1/contacts/import adds up to 50,000 contacts in one request, and a campaign texts everyone in an audience, instead of one POST /v1/messages per person.

Rate limit headers#

Every answer to a request with an API key carries these headers:

X-RateLimit-Limitinteger

Requests allowed per minute with this API key.

X-RateLimit-Remaininginteger

Requests left in the current minute.

X-RateLimit-Resetinteger

When the current minute ends and the count starts again, in Unix seconds.

Retry-Afterinteger

Seconds to wait before trying again.

Over the limit#

A request over the limit is refused with 429 and the code rate_limited. Retry-After says how many seconds to wait:

Response ยท 429
HTTP/1.1 429 Too Many Requests
Retry-After: 12
X-RateLimit-Limit: 600
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1795712760
X-Request-Id: req_8Fk2LqZ9xW1v
Content-Type: application/json

{
  "error": {
    "code": "rate_limited",
    "message": "Too many requests: up to 600 a minute per API key. Wait a moment and try again.",
    "requestId": "req_8Fk2LqZ9xW1v"
  }
}

Back off and retry#

  • On 429, wait the seconds in Retry-After, then try again.
  • On 5xx answers and network errors, wait a little longer each time (exponential backoff), with some randomness so many workers do not retry in step.
  • Retry POSTs with the same Idempotency-Key: then a request that did go through the first time is not done twice.
  • Give up after a few tries and log the error with its request id.
// Retries 429s (after Retry-After), 5xx answers and network errors, up to 5 tries.
// A POST keeps the same Idempotency-Key on every try, so nothing is done twice.
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const backoff = (n) => Math.min(30_000, 500 * 2 ** n) * (0.5 + Math.random() / 2);

export async function smsblast(method, path, body) {
  const key = crypto.randomUUID();
  for (let attempt = 0; ; attempt++) {
    const last = attempt === 4;
    let res;
    try {
      res = await fetch(`https://app.smsblast.net${path}`, {
        method,
        headers: {
          Authorization: `Bearer ${process.env.SMSBLAST_API_KEY}`,
          ...(method === 'POST' ? { 'Idempotency-Key': key } : {}),
          ...(body ? { 'Content-Type': 'application/json' } : {}),
        },
        body: body ? JSON.stringify(body) : undefined,
      });
    } catch (err) {
      if (last) throw err;
      await sleep(backoff(attempt));
      continue;
    }
    if ((res.status !== 429 && res.status < 500) || last) return res;
    const wait = res.status === 429 ? Number(res.headers.get('Retry-After') || 1) * 1000 : backoff(attempt);
    await sleep(wait);
  }
}

const res = await smsblast('POST', '/v1/messages', { to: '+14155550101', body: 'Your order is ready.' });
console.log(res.status, await res.json());
import os
import random
import time
import uuid

import requests

API = "https://app.smsblast.net"


def backoff(attempt):
    return min(30, 0.5 * 2 ** attempt) * random.uniform(0.5, 1)


def smsblast(method, path, body=None, tries=5):
    """Retries 429s (after Retry-After), 5xx answers and network errors.
    A POST keeps the same Idempotency-Key on every try, so nothing is done twice."""
    headers = {"Authorization": f"Bearer {os.environ['SMSBLAST_API_KEY']}"}
    if method == "POST":
        headers["Idempotency-Key"] = str(uuid.uuid4())
    for attempt in range(tries):
        last = attempt == tries - 1
        try:
            res = requests.request(method, API + path, headers=headers, json=body, timeout=30)
        except requests.RequestException:
            if last:
                raise
            time.sleep(backoff(attempt))
            continue
        if (res.status_code != 429 and res.status_code < 500) or last:
            return res
        if res.status_code == 429:
            time.sleep(int(res.headers.get("Retry-After", "1")))
        else:
            time.sleep(backoff(attempt))


res = smsblast("POST", "/v1/messages", {"to": "+14155550101", "body": "Your order is ready."})
print(res.status_code, res.json())

Signup forms#

The public form endpoint POST /v1/public/forms/{publicId} needs no key, so it is limited by IP address instead: up to 20 in 10 minutes per IP address.