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
| Code | HTTP | Meaning |
|---|---|---|
missing_token | 401 | No Authorization header was presented |
invalid_token | 401 | Malformed, unknown, or revoked token |
plan_required | 403 | The account's plan does not include API access — or the account is suspended (see below) |
insufficient_scope | 403 | Token is valid but lacks the required scope |
upgrade_required | 403 | The plan lacks the feature, or a quota is spent |
validation_failed | 400 | Request body or query parameters were rejected |
not_found | 404 | No such resource, or no such path |
method_not_allowed | 405 | The path exists but not for this HTTP method |
conflict | 409 | Well-formed, but the current state refuses it |
idempotency_key_reuse | 409 | An Idempotency-Key was reused for a different body, or its first request is still in flight |
rate_limited | 429 | Fixed window exhausted — see rate limits |
internal_error | 500 | Something 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_requiredis also non-retryable until the plan changes; surface it to whoever owns the account. - 403 with
upgrade_requiredbehaves the same way: back off and surface it. It is never a request bug. - 403 with
insufficient_scopemeans the token exists but is too narrow: create a token with the scope the endpoint documents. - 400 with
validation_failedis 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_allowedis also your bug: the path is right, the verb is not. - 409 with
conflictmeans 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-Afterinterval. - 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."}}