# Error codes

Every SDK answers the same codes with the same statuses; `tools/docs.py` checks this table and every language guide
against the verifier.

A refusal is `application/problem+json` with `type: https://allowedby.org/errors/<code>`. A `401` that the agent can
resolve also carries a challenge in `WWW-Authenticate: AllowedBy ...` (ABY-2 §6). `429` and `503` carry `Retry-After`.

| Code | Status | Meaning | What to do |
|---|---|---|---|
| `invalid_request` | 400 | Malformed request: the body is not a JSON object, a header is repeated or unreadable | Fix the request |
| `passport_required` | 401 | No `Allowed-By` header | The agent gets a passport from its node and retries |
| `invalid_signature` | 401 | A signature, proof, chain or `human_sig` check failed, or the proof was replayed | The agent signs a fresh proof; check its clock (-120 s to +60 s) |
| `untrusted_node` | 401 | The grant or passport comes from a node this service does not trust | Use a trusted node, or add it (trust list) |
| `insufficient_witnesses` | 401 | The node's log is not cosigned by enough trusted witnesses | Retry later; the node operator fixes its witnesses |
| `grant_required` | 401 | The route needs a person's approval and the agent showed only its passport | The agent asks the person (the challenge says what) |
| `grant_insufficient` | 401 | The grant does not cover this request (capability, scope, amount, audience, initiator) | The agent asks for a grant that covers it |
| `level_insufficient` | 401 | The person's identity level is below the route's | The person verifies their identity to that level |
| `qes_required` | 401 | The route needs a qualified electronic signature | The person signs with a qualified signature |
| `authority_required` | 401 | The organisation's co-approvers have not approved | The co-approvers approve |
| `mandate_required` | 401 | The route needs a company mandate | The person acts with their company's mandate |
| `expired` | 401 | The grant has expired | The agent asks again |
| `not_yet_valid` | 401 | The grant's `nbf` is in the future | Check clocks; retry |
| `revoked` | 401 | The person or the node withdrew the grant | The agent asks again; respect the person's choice |
| `actor_expired` | 401 | The agent's key (passport) expired | The agent gets a new passport and rebinds its grants |
| `class_lifetime_exceeded` | 401 | The grant lives longer than the route's class allows | The agent asks for a shorter grant |
| `single_use_consumed` | 401 | A one-time grant was already used | The agent asks again for this request |
| `capability_denied` | 403 | Not allowed at all (route unknown, operator not accepted, over a ceiling) | Do not retry |
| `tier_insufficient` | 403 | The agent's key custody or the passkey kind is too weak | Use a stronger custody tier or passkey |
| `human_not_linked` | 403 | The person has not linked their account here | The person links their account (`aby:link`) |
| `budget_exceeded` | 403 | The organisation's budget for this action is used up | Wait for the next period or raise the budget |
| `rate_limited` | 429 | Too many requests from this agent or operator | Wait (`Retry-After`) |
| `envelope_too_large` | 431 | `Allowed-By` and `AllowedBy-Proof` over 8 KiB, or a chain of more than two grants (depth 1) | Send a shorter chain |
| `status_stale` | 503 | The revocation list is too old to decide, or the replay store is unavailable | Retry after `Retry-After` |

## How an agent reacts

- **Asks the person, then retries once:** `grant_required`, `grant_insufficient`, `level_insufficient`, `qes_required`,
  `expired`, `revoked`, `class_lifetime_exceeded`, `single_use_consumed`.
- **Gets a new passport or rebinds:** `passport_required`, `actor_expired`.
- **Waits, then retries:** `rate_limited`, `status_stale`.
- **Signs again, once:** `invalid_signature` (a fresh proof; check the clock and the URL).
- **Stops:** every other code. Retrying cannot succeed until someone changes something.
