API

Errorsv1

Understand error shapes, status codes, and how to debug failures fast.

What an error looks like

SendLib returns JSON errors. Depending on the deployment/version, you may see either:

  • A simple error object
  • A standard envelope that includes data, meta, and error

Be liberal in what you accept

When writing SDKs/integrations, handle both shapes so you don't break when the platform upgrades.

Simple error body

json
{
  "error": {
    "type": "invalid_request",
    "message": "Human-readable message",
    "code": "OPTIONAL_MACHINE_CODE",
    "details": {"any": "shape"}
  }
}
json
{
  "data": null,
  "meta": {
    "request_id": "abc123/xyz789-000001",
    "timestamp": "2026-02-05T12:00:00.000Z"
  },
  "error": {
    "type": "unauthorized",
    "message": "Invalid credentials",
    "code": "",
    "details": null
  }
}

Request IDs

When present, meta.request_id is also returned as X-Request-ID.

Include request IDs in bug reports

If you're contacting support or debugging with logs, include X-Request-ID and the approximate timestamp.

Common status codes

StatusMeaningWhat to do
400Invalid request (malformed JSON, validation)Fix the payload; log the error details.
401Missing/invalid credentialsCheck Authorization: Bearer ... and key validity.
403Authenticated but not allowedAdd the missing scope or use a different key.
404Not foundDouble-check the resource id and base path.
409ConflictUsually "already exists" or state conflict; read message.
415Unsupported media typeSet Content-Type: application/json.
422Unprocessable entityTreat as semantic validation (often per-recipient rejects).
429Rate limitedBackoff + retry later; see rate limits.
500Internal server errorRetry with backoff; include request id if persistent.
502Upstream failureRetry with idempotency if the request creates something.

Handling errors in code

  • Treat 4xx as "fix the request or permissions".
  • Treat 5xx/502 as transient unless proven otherwise.
  • For create-style endpoints, combine retries with Idempotency.
ts
const res = await fetch("https://api.sendlib.com/v1/transmissions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SENDLIB_API_KEY}`,
    "Idempotency-Key": "0d6c2a6f-3f3c-4d4a-9c1a-2f7f9c1a1f0b",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ /* ... */ }),
});
 
if (!res.ok) {
  const text = await res.text();
  throw new Error(`SendLib error ${res.status}: ${text}`);
}

Next