Errors and rate limits
A request either succeeds with a 2xx status or fails with a JSON body that says why. Branch on error.code, wait out a 429 using the Retry-After header, and keep an eye on your credit balance.
Related:Email validationEmail sending
Checked against the API source on
HTTP status codes
| Status | Meaning | Typical cause |
|---|---|---|
| 200 | OK | Successful read or update. |
| 201 | Created | A domain, template, campaign or suppression was created. |
| 202 | Accepted | An email, bulk send or bulk validation job was queued. Work continues in the background. |
| 204 | No content | A delete succeeded. |
| 400 | Bad request | A field is missing or invalid, or a sending rule refused the request (unverified domain, a From address that is not on the sending domain, suppressed recipient, no DMARC for a bulk send). |
| 402 | Payment required | Not enough credits for this request. |
| 401 | Unauthorized | No key, an unknown, deactivated or expired key, or an IP that is not on the key's allow-list. The response has a WWW-Authenticate header. See Authentication. |
| 403 | Forbidden | The key is valid but lacks the endpoint's scope. |
| 404 | Not found | No such item on your account. A path typed without its trailing slash also returns 404, as a plain HTML page rather than JSON. |
| 413 | Payload too large | The request body is too large, usually attachments. |
| 429 | Too many requests | You hit your plan's hourly limit (the response has a Retry-After header), or your plan does not include the feature you asked for. |
| 500 | Server error | An unexpected fault on our side. Retry with backoff; the response never exposes internals. |
| 502, 503 | Service unavailable | The sending service could not be reached. Retry with backoff. Credits are returned for a send that was not accepted. |
The error body
Validation endpoints and everything the framework rejects use one envelope. Read error.code, which is stable, rather than the message text, which is for humans.
{
"success": false,
"error": {
"code": "validation_error",
"message": "email: Enter a valid email address.",
"details": [
{ "field": "email", "issue": "Enter a valid email address." }
]
}
}| Field | Description |
|---|---|
| success | Always false on an error. |
| error.code | A stable machine-readable code, from the table below. |
| error.message | A short human summary. For a field error it reads field: issue. |
| error.details | A list of {field, issue}, one per problem. field is a dotted path such as recipients.0.email, or non_field_errors for request-level problems. |
| error.meta | Optional extras. On 429 it carries retry_after, retry_after_human, plan, current_limit and upgrade_url. |
| Retry-After (header) | On 429, the number of seconds to wait, the same value as error.meta.retry_after. |
| error.code | Status | Meaning |
|---|---|---|
| validation_error | 400 | The request body or query failed validation. |
| authentication_required | 401 | No credentials were sent. |
| invalid_credentials | 401 | Credentials were sent and rejected: unknown, deactivated or expired key, wrong header format, or an IP that is not allowed. |
| permission_denied | 403 | Authenticated, but not allowed: the key lacks the required scope. |
| not_found | 404 | The item does not exist on your account. |
| insufficient_credits | 402 | Not enough credits for this request. |
| rate_limit_exceeded | 429 | Throttled by your plan's limits. |
| payload_too_large | 413 | The request body exceeds the size limit. |
| internal_error | 500 | An unexpected server error. |
| api_error | varies | A fallback for anything not covered above. |
{
"success": false,
"error": {
"code": "insufficient_credits",
"message": "Insufficient credits. Please purchase more credits.",
"details": [
{ "field": "non_field_errors", "issue": "Insufficient credits. Please purchase more credits." }
]
}
}{
"error": "Insufficient credits. Please purchase more credits."
}Credits and 402
Validation and sending each have their own balance. A single validation costs 1 validation credit, even in fast mode or when the answer is cached. A sent email costs 1 sending credit. When the relevant balance cannot cover the request, the API answers 402 and does nothing.
- Single validation: the credit is reserved atomically, so two parallel calls on a 1-credit balance cannot both succeed.
- Bulk validation: the call checks that your balance covers the whole list, then the job spends 1 credit per address as it processes them.
- Single send: the credit is taken first and given back if the message is refused or cannot be handed to the sending service.
- Bulk send and campaigns: the whole list is charged up front. Credits for recipients that were skipped or not handed off are returned when the run finishes.
Top up in the app, or move to a plan with a bigger allowance. See pricing.
Rate limits
Validation requests (single and bulk) are limited per account, per hour, according to your plan. The limit counts all your keys together. When you go over, the API answers 429 with error.code rate_limit_exceeded, and tells you how long to wait in a Retry-After header and in the body.
{
"success": false,
"error": {
"code": "rate_limit_exceeded",
"message": "Request was throttled. Expected available in 1742 seconds.",
"details": [
{ "field": "non_field_errors", "issue": "Request was throttled. Expected available in 1742 seconds." }
],
"meta": {
"retry_after": 1742,
"retry_after_human": "29 minutes",
"plan": "Free",
"current_limit": "10 requests/hour",
"upgrade_url": "/scrubimail/api/v1/plans/"
}
}
}| Plan | Validation requests per hour | Bulk validation | Largest bulk request |
|---|---|---|---|
| Free | 10 | Not included | - |
| Starter | 100 | Included | 5,000 |
| Professional | 500 | Included | 25,000 |
| Business | 1,000 | Included | 100,000 |
| Enterprise | 10,000 or more: not limited | Included | 500,000 |
These are the plan defaults in our code. Your plan's live values are max_api_calls_per_hour and max_bulk_emails in the public GET /plans/ response, and plans and prices are on the pricing page. A single bulk request is also capped at 10,000 addresses by the endpoint itself, whatever your plan allows. A bulk request over the limit gets an error that states the limit and the number of addresses you requested.
The hourly request limit applies to the validation endpoints. Sending endpoints are not counted against it: sending is governed by your credits, your verified domain, and delivery pacing. Lookups such as history, analytics and domain reputation are not counted either.
Retrying safely
- Retry
429after the number of seconds in theRetry-Afterheader (orerror.meta.retry_after), only when it is present. - Retry
500,502and503with exponential backoff and jitter, for example 1s, 2s, 4s, up to a few attempts. - Do not blindly retry
400,401,402or403. They fail the same way until you change something. - A repeated
POST /send/can send a second email. If you did not receive a response, checkGET /send/history/before you retry.
async function scrubimail(path, init, attempts = 4) {
for (let i = 0; i < attempts; i++) {
const res = await fetch(`https://api.scrubimail.com/scrubimail/api/v1${path}`, {
...init,
headers: { "X-API-Key": process.env.SCRUBIMAIL_API_KEY, "Content-Type": "application/json", ...init?.headers },
});
if (res.ok) return res.json();
const body = await res.json().catch(() => ({}));
const err = typeof body.error === "string" ? { message: body.error } : body.error ?? {};
const wait = Number(res.headers.get("Retry-After") ?? err.meta?.retry_after);
if (res.status === 429 && wait) {
await new Promise((r) => setTimeout(r, wait * 1000));
} else if (res.status >= 500) {
await new Promise((r) => setTimeout(r, 2 ** i * 1000 + Math.random() * 250));
} else {
throw Object.assign(new Error(err.message ?? res.statusText), { status: res.status, code: err.code });
}
}
throw new Error("ScrubiMail request failed after retries");
}import os, random, time, requests
BASE = "https://api.scrubimail.com/scrubimail/api/v1"
def scrubimail(method, path, attempts=4, **kwargs):
headers = {"X-API-Key": os.environ["SCRUBIMAIL_API_KEY"], **kwargs.pop("headers", {})}
for i in range(attempts):
res = requests.request(method, BASE + path, headers=headers, timeout=30, **kwargs)
if res.ok:
return res.json() if res.content else None
body = res.json() if res.content else {}
err = body.get("error") or {}
if isinstance(err, str):
err = {"message": err}
retry_after = res.headers.get("Retry-After") or (err.get("meta") or {}).get("retry_after")
if res.status_code == 429 and retry_after:
time.sleep(float(retry_after))
elif res.status_code >= 500:
time.sleep(2 ** i + random.random() * 0.25)
else:
raise RuntimeError(f"{res.status_code} {err.get('code')}: {err.get('message')}")
raise RuntimeError("ScrubiMail request failed after retries")Something missing or wrong? Email [email protected].