usend Docs
API reference

Errors

The error object and every error the API returns.

Failed requests return a non-2xx HTTP status and an error object:

JSON
{
  "statusCode": 422,
  "name": "validation_error",
  "message": "The `to` field is required."
}
FieldDescription
statusCodeThe HTTP status code.
nameA stable, machine-readable error name. Use it in your code.
messageA human-readable explanation. It may change: don't parse it.

Error names

StatusNameDescription
401missing_api_keyThe Authorization header is missing or not in the form Bearer <key>.
401restricted_api_keyA sending_access key called an endpoint that needs full_access.
403restricted_api_keyA domain-restricted key tried to send from another domain.
403invalid_api_keyThe API key does not exist or was deleted.
403forbiddenThe request is not allowed. The message explains why: the sending domain is not verified, a recipient is not allowed in the sandbox, broadcasts are not available, no member has verified their email, or the organization is suspended.
403invalid_download_linkAn attachment download link is invalid or expired.
404not_foundThe resource or endpoint does not exist, or belongs to another organization.
405method_not_allowedThe endpoint does not support this HTTP method.
409conflictThe resource already exists (a domain, a contact in an audience, a template alias) or is in use.
409invalid_idempotency_keyThe idempotency key was already used for another email.
409concurrent_idempotent_requestsAnother request with the same idempotency key is in progress.
413payload_too_largeThe request body is larger than 50 MB.
422validation_errorA parameter is missing or invalid, or the action is not possible in the resource's current state (for example, canceling an email that is no longer scheduled).
422dns_provider_errorAuto-configure got an unexpected error from the DNS provider.
429rate_limit_exceededToo many requests. See Rate limits.
429daily_quota_exceededThe organization reached its daily sending quota.
429monthly_quota_exceededThe organization reached its monthly sending quota.
500internal_server_errorSomething went wrong on our side. Retry later.

Handling errors

  • 4xx errors mean the request needs to change. Retrying the same request gives the same result, except for 429 and 409 concurrent_idempotent_requests.
  • 429 rate_limit_exceeded: wait for the retry-after header, then retry.
  • 5xx errors can be retried with backoff. Use an idempotency key when retrying sends.

The SDKs give you the same fields. In Node.js, the error object is returned as error instead of being thrown. In Python, the SDK raises UsendError:

Node.js
const { data, error } = await usend.emails.send(email);
if (error) {
  if (error.name === 'rate_limit_exceeded') {
    // wait, then retry
  }
  console.error(error.statusCode, error.name, error.message);
}

Network failures use the name application_error and have no status code.