> ## Documentation Index
> Fetch the complete documentation index at: https://docs.klatt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> The error response format of the Klatt API, its status codes, the credential error codes and when to retry.

The API uses standard HTTP status codes. Errors return a JSON body.

## Error format

```json theme={null}
{
  "detail": "agent_not_found"
}
```

* `detail` is usually a **stable code** in lowercase with underscores, such as `agent_not_found` or `contact_list_not_found`. Match on the code, not on the HTTP reason phrase.
* A few authentication errors carry a short **text** in `detail`, such as `Invalid or expired API key`.
* Errors raised before a request reaches the API can add a human-readable `message`.
* For `422`, `detail` is usually a **list** of field errors, each with `loc` (where the problem is), `msg` and `type`. Some refusals return a string code instead, and a few return an object with a `code`. Handle all three shapes.

```json theme={null}
{
  "detail": [
    {
      "type": "string_too_short",
      "loc": ["body", "name"],
      "msg": "String should have at least 1 character"
    }
  ]
}
```

## Status codes

| Status | Meaning |
| - | - |
| `200`, `201`, `204` | Success. `201` creates a resource; `204` has no body. |
| `304` | The conversation list has not changed since the `ETag` you sent. |
| `401` | Authentication failed. See below. |
| `403` | The key is valid but may not do this. |
| `404` | The resource does not exist in your organization. Resources of other organizations also answer `404`. |
| `409` | The request conflicts with the current state, for example a duplicate contact field key. |
| `412`, `428` | Permanent document deletion: the `If-Match` header is stale (`412`) or missing (`428`). See below. |
| `422` | The request failed validation. |
| `429` | The key exceeded its rate limit. See [Rate limits](https://docs.klatt.ai/api-reference/rate-limits.md). |
| `5xx` | A failure on Klatt's side. |

Each operation in the reference lists the `404`, `409` and `5xx` responses it can return.

## Permanent document deletion

`404`, `412` and `428` from the permanent document deletion do not use `detail`. They return `{"error_code": "...", "preview": {...}}`, where `error_code` is `resource_not_found`, `deletion_preview_changed` (`412`) or `if_match_required` (`428`). A `412` returns the fresh `preview` and its `ETag` header, so you can show the change and retry with the new `ETag` without requesting another preview.

## Credential errors

These `401` codes come with a `message`:

| `detail` | Cause |
| - | - |
| `api_key_required` | No API key was sent, or more than one credential was sent. |
| `console_token_not_accepted` | The `Authorization` header is not `Bearer <organization API key>`. This includes a console sign-in token and a key sent without the `Bearer ` prefix. |
| `api_key_wrong_host` | An API key was sent to the console host. Use `https://api.klatt.ai`. |

An unknown or deleted key answers `401` with `detail` set to `Invalid or expired API key`. The text is literal: keys do not expire.

## Rate limit and availability codes

* `429` with `detail` `rate_limited`: slow down and retry after the number of seconds in the `Retry-After` header.
* `503`: a dependency the request needs is temporarily unavailable, and `detail` names it, for example `rate_limit_unavailable` (the API could not count your request) or `contacts_unavailable`. Retry with backoff.

## Retrying

* Retry `429` and `503` (and other `5xx` on read operations) with exponential backoff and jitter, honoring `Retry-After` when present.
* Do not retry other `4xx` errors without changing the request. They will fail again.
* Creating operations are not idempotent: a retried `POST` can create a second resource. After a timeout, list the resource to check whether the first request succeeded.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.