# Errors

> The error format of the Duty API, its HTTP statuses and every error key with its message.

An error answers a `4xx` or `5xx` status and a body with a stable key, a readable message and the ID of the call:

```json
{
  "error": "VALIDATION_ERROR",
  "message": "Check the data you sent",
  "traceId": "4f0c2a9e-6f1d-4c55-9d1e-2b7f3f2c8a10",
  "fields": [
    { "field": "contact.email", "message": "Must be a valid email address" },
    { "field": "subject", "message": "Must be at least 3 characters long" }
  ]
}
```

| Field | Meaning |
| --- | --- |
| `error` | Stable key. Branch on it in your code. |
| `message` | Explanation for people, in the language of `Accept-Language`. It may change; don't parse it. |
| `traceId` | ID of the call, also in the `X-Request-ID` header. Quote it to support. |
| `fields` | Only for validation errors: each invalid field, by its path in the body (`contact.email`), with its message. |
| `data` | Only on some errors: values that help you react, such as the limit that was reached. |

## Handling errors

- **400 and 422**: fix the request. Show `fields` next to your form inputs.
- **401**: the key is missing, wrong, revoked or expired.
- **403**: the key lacks a scope, the plan does not include the API, the subscription is read-only, or a plan limit was reached.
- **404**: the request, attachment or webhook does not exist in this workspace.
- **409**: the request changed meanwhile or is in a state that does not allow the change. Read it again and decide.
- **429**: slow down and retry after `Retry-After` seconds. See [Rate limits](/en/api/rate-limits/).
- **5xx**: retry with exponential backoff. Requests that open a resource are not idempotent: read before retrying a `POST` that may have succeeded.

## Error keys

Validation messages inside `fields` use their own keys (`VALIDATION_REQUIRED`, `VALIDATION_MAX_LENGTH`…); rely on `field` to tell them apart and show `message` as is.
