Skip to main content
ScrubiMail

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 codes the API returns
StatusMeaningTypical cause
200OKSuccessful read or update.
201CreatedA domain, template, campaign or suppression was created.
202AcceptedAn email, bulk send or bulk validation job was queued. Work continues in the background.
204No contentA delete succeeded.
400Bad requestA 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).
402Payment requiredNot enough credits for this request.
401UnauthorizedNo 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.
403ForbiddenThe key is valid but lacks the endpoint's scope.
404Not foundNo such item on your account. A path typed without its trailing slash also returns 404, as a plain HTML page rather than JSON.
413Payload too largeThe request body is too large, usually attachments.
429Too many requestsYou hit your plan's hourly limit (the response has a Retry-After header), or your plan does not include the feature you asked for.
500Server errorAn unexpected fault on our side. Retry with backoff; the response never exposes internals.
502, 503Service unavailableThe 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.

Error envelope
{
  "success": false,
  "error": {
    "code": "validation_error",
    "message": "email: Enter a valid email address.",
    "details": [
      { "field": "email", "issue": "Enter a valid email address." }
    ]
  }
}
Envelope fields
FieldDescription
successAlways false on an error.
error.codeA stable machine-readable code, from the table below.
error.messageA short human summary. For a field error it reads field: issue.
error.detailsA 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.metaOptional 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 codes
error.codeStatusMeaning
validation_error400The request body or query failed validation.
authentication_required401No credentials were sent.
invalid_credentials401Credentials were sent and rejected: unknown, deactivated or expired key, wrong header format, or an IP that is not allowed.
permission_denied403Authenticated, but not allowed: the key lacks the required scope.
not_found404The item does not exist on your account.
insufficient_credits402Not enough credits for this request.
rate_limit_exceeded429Throttled by your plan's limits.
payload_too_large413The request body exceeds the size limit.
internal_error500An unexpected server error.
api_errorvariesA 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." }
    ]
  }
}

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.

429 response
{
  "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/"
    }
  }
}
Request limits by plan
PlanValidation requests per hourBulk validationLargest bulk request
Free10Not included-
Starter100Included5,000
Professional500Included25,000
Business1,000Included100,000
Enterprise10,000 or more: not limitedIncluded500,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 429 after the number of seconds in the Retry-After header (or error.meta.retry_after), only when it is present.
  • Retry 500, 502 and 503 with exponential backoff and jitter, for example 1s, 2s, 4s, up to a few attempts.
  • Do not blindly retry 400, 401, 402 or 403. 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, check GET /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");
}

Something missing or wrong? Email [email protected].