Status codes, the error shape and what to do about each.
Every refusal is JSON with one field, detail, written for a person to read. Show it to your user as it is.
HTTP/1.1 403 Forbidden
{"detail": "This API key does not have the “sites:write” permission."}
A request body that doesn't fit the schema answers 422, and detail is a list naming each field:
{"detail": [{"type": "missing", "loc": ["body", "data", "image"], "msg": "Field required"}]}
| Status | Means | What to do |
|---|---|---|
| 200 · 201 | Done. 201 when something new was made. | Read the body. |
| 202 | Accepted, and finishing in the background (a registration, a move, a renewal). | Read the thing's status later, or listen to a webhook. |
| 204 | Done, nothing to return (a deletion). | Nothing. |
| 400 | The request made sense but can't be done as asked: a bad image reference, a size we don't have, a value that won't do. | Fix the input; detail says what. |
| 401 | No key, a revoked or expired one, or a token the server doesn't know. | Make a new key in the panel. The CLI says run lh login. |
| 402 | The wallet is short for a paid call. | Top up, then send the call again with the same Idempotency-Key. |
| 403 | The key lacks the permission, a partner key can't act for that client, or the thing is managed by us and can't be changed. | Use a key with the permission, or stop. |
| 404 | Nothing by that name on this account. Also what you get for someone else's. | Check the name and the account you act for. |
| 409 | A conflict: the name is taken, a site by that slug exists, nothing is owed yet, a checklist item blocks publishing. | Read detail; often the state has moved on. |
| 413 | The body is too big. | Send less. |
| 422 | The body doesn't match the schema, or a DNS record isn't valid. | Fix the fields detail lists. |
| 429 | Too many requests, or a limit per number or per hour (one-time codes). | Wait and try again. |
| 5xx | Our problem. | Try again in a moment; paid calls stay safe with an Idempotency-Key. |
lh turns these into one line on stderr, prefixed lh:, and an exit code your scripts can branch on. The exit codes are on the command-line page.