# Errors

> Status codes and error bodies, and what to do about each.

Source: https://docs.ligament.ai/developers/errors/

When a call fails, the HTTP status tells you what kind of problem it is and the JSON body tells you which one. Permission errors carry a stable `code` your code can branch on, a `message` for logs and a `fix` written for the person (or agent) who has to sort it out. Show the `fix` to whoever can act on it rather than swallowing it.

All bodies on this page are real responses, with the host swapped for `https://app.ligament.ai`.

## Status codes

| Status | Meaning | What to do |
| --- | --- | --- |
| `400` | The request body isn’t valid JSON, or a header value is malformed | Fix the request |
| `401` | No usable credential: the key is wrong, revoked or missing | Check the `Authorization` header and the key |
| `403` | The credential is valid but not allowed to do this | Read `code` and `fix` (below) |
| `404` | The entity, record, workflow or endpoint doesn’t exist in this workspace | Check the key or id, and that the key belongs to the right workspace |
| `409` | The request conflicts with the record’s current state | Re-read the record, then retry with a valid change |
| `413` | The body is too large (inbound hooks accept up to 256 KB) | Send less |
| `422` | The body is understood but the values aren’t valid | Fix the values named in `error` |
| `429` | Too many calls to a rate-limited endpoint, such as starting workflow runs | Wait for the number of seconds in `Retry-After`, then retry |
| `5xx` | Something went wrong on our side | Retry with backoff; contact support if it persists |

## 401: no usable key

A key that doesn’t exist or has been revoked:

```plaintext
HTTP/1.1 401 Unauthorized
{"error":"Invalid or revoked API key"}
```

If you leave the `Authorization` header out entirely (and aren’t signed in), the answer is a `401` with a code and a fix:

```plaintext
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer
{"error":"This request has no credential: send an API key, or sign in.","code":"unauthenticated","message":"This request has no credential: send an API key, or sign in.","fix":"Send the header \"Authorization: Bearer <your API key>\". Create a key in Settings → API keys.","doc_url":"https://docs.ligament.ai/developers/api-keys/"}
```

Pages in the app (anything outside `/api`) still redirect to the sign-in page.

## 403: the four kinds

Every `403` from the key check has the same shape:

```json
{ "error": "…", "code": "…", "message": "…", "fix": "…", "required": ["…"], "route": "…" }
```

`error` and `message` hold the same text. `required` lists the scope or capability that was missing, and `route` is the endpoint pattern that refused the call. A missing scope also carries `doc_url`, a link to the page that explains the scope.

### insufficient\_scope

The key doesn’t have the scope this endpoint needs. Here a read-only key tries to create an incident:

```json
{
  "error": "This API key lacks the \"records:write:incident\" scope.",
  "code": "insufficient_scope",
  "message": "This API key lacks the \"records:write:incident\" scope.",
  "fix": "Use a key that has \"records:write:incident\" (or \"*\"). Create one in Settings → API keys; the scopes are listed at https://docs.ligament.ai/reference/scopes/.",
  "required": ["records:write:incident"],
  "route": "/api/records/[entityKey]",
  "doc_url": "https://docs.ligament.ai/reference/scopes/"
}
```

Fix: use a key with the scope in `required`. If it’s an admin scope, the `fix` says so: `*` doesn’t include admin scopes, so the key must name it. The same code also appears when the key has the scope but its creator’s current role doesn’t allow it; the message then says the key is capped at its creator’s role. See [API keys and scopes](https://docs.ligament.ai/developers/api-keys/index.md#a-key-is-capped-at-its-creator).

### session\_required

The endpoint only accepts a signed-in browser session. Here a key with every admin scope tries to create another key:

```json
{
  "error": "POST /api/keys only accepts a signed-in browser session, not an API key.",
  "code": "session_required",
  "message": "POST /api/keys only accepts a signed-in browser session, not an API key.",
  "fix": "Do this from the Ligament web app while signed in. API keys cannot manage keys, per-user state or platform settings.",
  "route": "/api/keys"
}
```

Fix: do it in the app. No scope opens these endpoints to a key.

### key\_owner\_inactive

The person who created the key is no longer a member of the workspace (they left or were removed), so the key no longer works. The message says so, and the `fix` asks a current member to create a new key in **Settings › API keys** and revoke this one.

### capability\_required

People need a capability from their role to use the Build, AI, Admin, Logs and App store areas, and so do API keys: a key has the capabilities of the person who created it. A member without the Build capability who calls a Build endpoint from the app gets:

```json
{
  "error": "Only workspace admins, or roles with the Build capability, can use Build",
  "code": "capability_required",
  "message": "Only workspace admins, or roles with the Build capability, can use Build",
  "fix": "Ask a workspace admin for a role whose permission set has the build:use capability.",
  "required": ["build:use"],
  "route": "/api/scripts"
}
```

Some endpoints accept any one of several capabilities. Listing workflow runs (`GET /api/workflows/runs`) works with Build or Read logs, and `required` then lists both.

For an API key the `fix` says the key can do what its creator can do. Fix: an admin gives the person (or the key’s creator) a role with that capability, or you use a key created by someone who has it. See [Roles and permission sets](https://docs.ligament.ai/guides/access/roles-and-permission-sets/index.md).

## 403: access to records

When the key has the right scope but its creator’s role doesn’t grant access to the entity, the record service refuses with an access code and a link to an explanation:

```json
{
  "error": "Role \"member\" is not permitted to read \"equipment_loan\"",
  "code": "no_grant",
  "message": "Role \"member\" is not permitted to read \"equipment_loan\"",
  "fix": "… an admin can open it to staff …, or grant it in a permission set.",
  "explain": "/api/access/explain?entity=equipment_loan&action=read",
  "doc_url": "https://docs.ligament.ai/guides/access/why-can-i-see-this/"
}
```

(The `fix` is shortened here.) Call the `explain` path with the same key to see every step of the decision: which roles were considered, which rule matched and which fields would be hidden. [Why can I see this?](https://docs.ligament.ai/guides/access/why-can-i-see-this/index.md) explains the answer.

Some endpoints check the creator’s role directly and answer with a short body, for example `{"error":"Admins only"}`.

## 404: not found

```plaintext
HTTP/1.1 404 Not Found
{"error":"Entity \"incidents\" not found in this workspace"}
```

```plaintext
HTTP/1.1 404 Not Found
{"error":"Record not found"}
```

Entity keys are singular (`incident`, not `incidents`).

## 409: conflict

A state change that the record’s lifecycle doesn’t allow:

```plaintext
HTTP/1.1 409 Conflict
{"error":"Transition not allowed: in_progress → bogus_state"}
```

Spec and changeset calls answer `409` with the code `spec.conflict` when someone changed the artefact since you read it, and nothing is applied. The [CLI](https://docs.ligament.ai/developers/cli/index.md#exit-codes) turns this into exit code `2`.

## 422: validation

A required field is missing:

```plaintext
HTTP/1.1 422 Unprocessable Entity
{"error":"Field \"title\" is required"}
```

A request body that doesn’t match the endpoint’s shape lists the problem per field:

```plaintext
HTTP/1.1 422 Unprocessable Entity
{"error":{"formErrors":[],"fieldErrors":{"workflowId":["Required"]}}}
```

Creating a key with a scope that doesn’t exist is also a `422`, so a typo never turns into a broader key than you meant:

```json
{"error":"Unknown scope(s): record:read","code":"invalid_scope","invalid":["record:read"]}
```

## MCP errors

The [MCP server](https://docs.ligament.ai/developers/mcp/index.md#errors) wraps the same problems in JSON-RPC. A missing scope for one tool is a tool result with `isError: true`, not a failed request, so an agent can read the reason and carry on.
