# Errors and limits

## How errors look

REST answers with an HTTP status and a JSON body. `error` is a stable word you can test for, `message` is a sentence for people, `details` names fields when there are any.

```json
{ "error": "invalid_input", "message": "\"contract_type\" must be one of: nda, service, …", "details": { "contract_type": ["…"] } }
```

As MCP tools, the same errors come back as a tool result with `isError: true` and the text `Error (<error>): <message>`. Protocol errors (unknown method, unknown tool, broken JSON) are JSON-RPC errors.

| Status | `error` | Meaning | What to do |
|---|---|---|---|
| 401 | `missing_api_key`, `invalid_api_key` | No key, or it is unknown, revoked or expired. | Ask your principal for a valid key. Do not retry. |
| 403 | `scope_missing` | The key lacks the scope the operation needs. `details.needs` names it. | Ask for a key with that scope, or do without. |
| 403 | `forbidden` | Only the owner of the agreement may do this. | Stop. |
| 403 | `level_too_low`, `email_not_verified` | The account's identity level does not allow it yet. | Tell your principal to confirm the e-mail address. |
| 404 | `not_found`, `template_not_found` | Nothing with this id for this account. An agreement of somebody else looks the same as one that does not exist. | Check the id. |
| 409 | `conflict` | The state does not allow it: already completed, already cancelled, party already signed, draft already used. The message says which. | Read the state with `agreement_get` and decide again. |
| 409 | `not_completed` | The bundle exists only after completion. | Wait. |
| 409 | `not_connected` | The account is not connected to Telegram. | Your principal sends `/connect` to the bot. |
| 409 | `in_progress` | A call with the same idempotency key is still running. | Wait a few seconds and repeat with the same key. |
| 413 | `too_large` | The file is too large for this way of transfer. | Use the REST download or a multipart upload. |
| 422 | `invalid_input` | An argument is missing or wrong. | Correct it. |
| 422 | `cannot_create` | The agreement could not be built, for example template variables are missing. | The message lists what is missing. |
| 429 | `rate_limited` | Too many calls with this key. | Wait for `Retry-After` seconds. |
| 5xx | | A failure on our side. | A writing call may or may not have happened: read the state before you repeat it, or repeat with the same idempotency key. |

## Limits

- 120 calls a minute per key. The headers `X-RateLimit-Limit` and `X-RateLimit-Remaining` show where you stand.
- Up to 25 other parties per call; more can be added afterwards.
- A wording up to 200 000 characters. A file up to 48 MB by multipart upload, about 11 MB as base64.
- `document_content` as a tool returns files up to 5 MB; larger ones through `GET /v1/documents/{id}/content`.
- The bot writes to the same party at most once in six hours.
- Lists are paged with `limit` (up to 100) and `page`; `has_more` says whether another page exists.
- Times are ISO 8601 in UTC.

## Idempotency

Writing calls accept an idempotency key: the header `Idempotency-Key` in REST, the argument `idempotency_key` as a tool. A second call with the same key and the same key holder within 24 hours returns the first result with `"idempotent_replay": true` and creates nothing. Use it on every `agreement_create` and `document_deposit` that might be retried, with an id from your own system.

## What a writing call sets in motion

| Call | Outside effect |
|---|---|
| `agreement_create` | e-mail to every party with an address; a Telegram message to every party with a handle the bot may write to |
| `agreement_add_party` | the same for that party, unless `notify` is false |
| `agreement_remind`, `telegram_invite` | messages to parties that have not joined |
| `telegram_moderate` | the bot posts into the group |
| `agreement_cancel` | nothing is sent; inform the parties yourself |
| `document_deposit` | nothing is sent; the hash is anchored |

Ask your principal before the first four.
