# Errors

> The error shape, every status code the API returns, and the codes to branch on.

A failed call returns `success: false` and a message in `error`. Many refusals add a stable `code` for your code to branch on. Plan refusals also carry `plansUrl`.

```json
{ "success": false, "code": "template_not_ready", "error": "This template is still a draft. An owner or admin needs to finalise it before it can be sent." }
```

Branch on `code` when it is there. A few older refusals put their stable word in `error` instead, such as `api_key_expired`, `insufficient_scope` and `idempotency_key_reused`; they are listed below. Never branch on the wording of a message: it is written for people and can change.

## Status codes

| Status | When | Codes and messages |
| --- | --- | --- |
| `400` | The MCP server got a body that is not JSON. The REST API answers bad JSON with `422`. | JSON-RPC error `-32700` |
| `401` | The key is missing, wrong or past its expiry. | `invalid or missing API key`, `api_key_expired` |
| `402` | The workspace's plan does not include this. | `plan_feature`, `plan_limit` |
| `403` | The key may not do this, or the workspace is not active. | `insufficient_scope`, `forbidden`, `workspace suspended`, `workspace_pending`, `workspace_unavailable`, `legal_acceptance_required` |
| `404` | Not found in this workspace. Another workspace's ids are also `404`. | `not found`, `not_found` |
| `409` | The request is fine, but the current state refuses it. | `request already in progress`, `contract_risk_required`, `template_not_ready`, `version_mismatch`, `too_many_running`, `batch_finished`, `not_fixable` |
| `413` | The file is too big or has too many pages. | `file too large` |
| `415` | The upload is not a PDF or DOCX. | `unsupported file type` |
| `422` | The request failed a check. | `invalid request`, `idempotency_key_reused`, `esign_not_allowed`, `esign_ack_required` and the template codes below |
| `429` | Too many calls. Wait for the `Retry-After` header's seconds. | `rate limit exceeded`, `rate_limited` |
| `500` | Something went wrong on our side. Retry with the same `Idempotency-Key`. | `internal error` |

Each endpoint lists its own errors on its page in the [API reference](https://dev.appliflo.com/api).

## 401: the key

`invalid or missing API key` means the header is missing or the key is wrong or revoked. `api_key_expired` means the key passed the expiry date set when it was made. Make a new key in [Settings, API keys](https://appliflo.com/settings/api-keys). See [API keys and scopes](https://dev.appliflo.com/guides/api-keys).

## 402: the plan

```json
{
  "success": false,
  "code": "plan_feature",
  "error": "API keys are on the Business plan. This workspace is on Starter.",
  "plansUrl": "/pricing"
}
```

- `plan_feature`: the plan does not include the feature. API keys, for the REST API and the MCP server, are on the Business plan. Signing in to the MCP server from Claude.ai or ChatGPT works on every plan.
- `plan_limit`: the action would go over a plan limit, such as recipients on one envelope.

`plansUrl` is a path on appliflo.com. An owner or admin changes the plan in [Settings, Billing](https://appliflo.com/settings/billing). See [Plans and AI pages](https://dev.appliflo.com/guides/plans).

## 403: scope and workspace

`insufficient_scope` comes with `required_scope`, the scope the key is missing. `forbidden` means the key may not touch that item, for example deleting a document a person uploaded. A workspace that is suspended, waiting for approval or closed gets the matching message on every call.

## 409: state

| Code | What to do |
| --- | --- |
| `request already in progress` | A call with the same `Idempotency-Key` is still running. Wait, then retry with the same key. |
| `contract_risk_required` | An AppliFlo library contract that our lawyer has not reviewed. Send again with `risk_accepted: true` once your user accepts the risk. See [Send a saved template](https://dev.appliflo.com/guides/send-template#appliflo-library-contracts) and [Send to many](https://dev.appliflo.com/guides/send-to-many#appliflo-library-contracts). |
| `template_not_ready` | The saved template is still a draft. An owner or admin finalises it in the app. |
| `version_mismatch` | The template was finalised again since you read it. Read it again and send the new `version`. |
| `too_many_running` | Two batches are already sending. Wait for one, or cancel one. |
| `batch_finished` | The batch has already finished, so it cannot be cancelled. |
| `not_fixable` | Only a failed row can be fixed. |

Deleting a document that has been sent, and voiding an envelope whose status can't be voided, are also `409`.

## 422: checks

`invalid request` means the body did not match the endpoint's schema. Read its page in the [API reference](https://dev.appliflo.com/api). Other `422` codes:

| Code | Meaning |
| --- | --- |
| `idempotency_key_reused` | The `Idempotency-Key` was first used with a different request. Use a new key for a new request. See [Idempotency](https://dev.appliflo.com/guides/idempotency). |
| `esign_not_allowed` | The form must be signed by hand, such as USCIS I-130 or SSA SS-5. Download the filled PDF instead. See [Send for signature](https://dev.appliflo.com/guides/send-for-signature). |
| `esign_ack_required` | The form's agency may reject an electronic signature. Send again with the acknowledgement once your user agrees. |
| `missing_person`, `unknown_role`, `duplicate_email` | A template role has no person, a role key is wrong, or two roles share an email. |
| `role_owned_field`, `unknown_field`, `locked_field` | A prefill names a box a recipient fills, a box that does not exist, or a box the template locks. |
| `cc_invalid`, `subject_invalid` | A copy address or the subject is not valid. |
| `signature_not_adopted` | The template has a box the sender signs. Only a signed-in sender can send it, not an API key. |
| `too_many_rows`, `quota_exceeded`, `nothing_to_send` | Send to many: more than 500 rows, more envelopes than the month has left, or every row needs a fix. |
| `no_change` | A row fix that changes nothing. |

## 429: slow down

Every key has a budget per minute. When it runs out, the reply is `429` with a `Retry-After` header in seconds:

```http
HTTP/1.1 429 Too Many Requests
Retry-After: 17

{ "success": false, "error": "rate limit exceeded" }
```

Wait that long, then retry. See [Rate limits](https://dev.appliflo.com/guides/rate-limits).

Each workspace also has a daily envelope limit, lower while the workspace is new. Going over it is a `429` too, with a message saying to try again tomorrow.

## Other server errors

`502` means a connected CRM did not answer during a prefill. `503` means sending is paused on our side for a while, with a `code`. `504` means reading the form took too long; try again. For any `5xx`, retry with the same `Idempotency-Key` so nothing is done twice.
