Skip to main content

Errors

Every non-success response uses one JSON envelope, so a client needs one parser:

{
"error": {
"code": "invalid_token",
"message": "The API token is not valid or has been revoked."
}
}

code is the machine-readable identifier — stable strings, never renumbered or renamed within an API version. message is for humans and may change; do not branch on it.

The promise holds for every failure, including a path that matched no route at all — never a plain-text page or an empty body.

The codes​

CodeHTTPMeaning
missing_token401No Authorization header was presented
invalid_token401Malformed, unknown, or revoked token
plan_required403The account's plan does not include API access — or the account is suspended (see below)
insufficient_scope403Token is valid but lacks the required scope
upgrade_required403The plan lacks the feature, or a quota is spent
validation_failed400Request body or query parameters were rejected
not_found404No such resource, or no such path
method_not_allowed405The path exists but not for this HTTP method
conflict409Well-formed, but the current state refuses it
idempotency_key_reuse409An Idempotency-Key was reused for a different body, or its first request is still in flight
rate_limited429Fixed window exhausted — see rate limits
internal_error500Something failed on our side

plan_required and upgrade_required are separate on purpose: the first means this token cannot do that (mint a token with the right access), the second means your tier cannot do that (open the billing page). One code could not guide a client toward both fixes.

plan_required is reused for suspended accounts: the code stays plan_required (HTTP 403) and the message reads this account is suspended instead of the plan message. Branch on the code for control flow and surface the message to a human — the message tells you which of the two it was.

Handling guidance​

  • 401s are not retryable as-is. A missing/invalid token needs human action (create a new token). Retry loops that hammer 401s just burn your rate budget.
  • 403 with plan_required is also non-retryable until the plan changes; surface it to whoever owns the account.
  • 403 with upgrade_required behaves the same way: back off and surface it. It is never a request bug.
  • 403 with insufficient_scope means the token exists but is too narrow: create a token with the scope the endpoint documents.
  • 400 with validation_failed is your bug, not ours: the message names the field. Fixing the request and resending works; resending unchanged fails identically.
  • 404 on a resource you expected means it is gone or was never yours — re-read the collection before deciding it is an error.
  • 405 with method_not_allowed is also your bug: the path is right, the verb is not.
  • 409 with conflict means the state moved underneath you — a slug someone else claimed while your create was in flight. Re-read and choose again; retrying the identical request fails identically.
  • 429 is retryable after the Retry-After interval.
  • 500 is retryable with backoff. If it persists, contact support.

A worked example​

curl -i https://lsg.bio/api/v1/whoami -H "Authorization: Bearer lsgbio_wrong"
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="lsg.bio", error="invalid_token"
Content-Type: application/json

{"error":{"code":"invalid_token","message":"The API token is not valid or has been revoked."}}