> For the complete documentation index, see [llms.txt](https://docs.moderncollections.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.moderncollections.io/rest-api-explorer/welcome-to-the-modern-collections-api/error-envelope.md).

# Error envelope

All errors return a consistent JSON envelope:

```json
{
  "error": {
    "code": "validation_failed",
    "category": "invalid_request",
    "message": "debtor.state is required",
    "request_id": "req_01HZX2Y3K8N5R7Q9V4M6P1C0"
  }
}
```

| Status | Meaning                                                                                                                   |
| ------ | ------------------------------------------------------------------------------------------------------------------------- |
| `400`  | Bad request — fix the request body or query parameters.                                                                   |
| `401`  | Unauthorized — missing or invalid API key.                                                                                |
| `403`  | Forbidden — the key lacks permission for this resource.                                                                   |
| `404`  | Not found — the resource does not exist.                                                                                  |
| `409`  | Conflict — typically a duplicate `invoice_number` for the same debtor.                                                    |
| `422`  | Compliance refusal — the request violates a compliance gate.                                                              |
| `429`  | Rate limited — honor the `Retry-After` header.                                                                            |
| `5xx`  | Server error — retry with backoff. Persistent failures surface in our [status page](https://status.moderncollections.io). |

{% hint style="warning" %}
Always log the `request_id` from the response on your side. It's the fastest way for our support team to triage an issue.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.moderncollections.io/rest-api-explorer/welcome-to-the-modern-collections-api/error-envelope.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
