# Errors and rate limits

Source: https://amanucci.com/docs/developers/errors

> The application/problem+json error envelope, the status codes and types the Amanucci API returns, and its rate-limit headers.

## The error envelope

Every refusal is an RFC 9457 problem, with content type `application/problem+json`:

```json
{
  "type": "period_not_locked",
  "title": "A filing is generated from a locked period only",
  "status": 409,
  "detail": "…",
  "instance": "/v1/entities/0192f0c4-.../filings"
}
```

| Member | Meaning |
| --- | --- |
| `type` | the machine-readable code. Branch on this. |
| `status` | the HTTP status, repeated |
| `title` | a human summary of the type, stable per type |
| `detail` | a human summary of this occurrence (may be absent) |
| `instance` | the request path |

`title` and `detail` are prose for people. Do not parse them. A few types add a member a client needs to act, such as `findings` on an e-invoice that fails validation, or `instructions` and `windowSeconds` on `step-up-required`.

## Status codes

| Status | When | Example types |
| --- | --- | --- |
| 401 | no credential, or one that is no longer valid | `unauthenticated` |
| 403 | authenticated but refused: role, grant, seat or step-up | `step-up-required`, `grant-required`, `seat-required`, `authority-required`, `signing-reserved` |
| 404 | absent, or hidden from you (the two look the same) | `not-found`, `document_not_found` |
| 409 | a conflict: a stale version, or a transition not allowed now | `period_not_locked`, `filing_exists` |
| 410 | something that existed and is closed for good | `invite_expired`, `invite_revoked` |
| 422 | the request did not satisfy the schema, or a domain rule refused it | `invalid-input`, `batch_full` |
| 429 | too many requests | `rate-limited` |
| 503 | temporarily unavailable; retry after `Retry-After` | `rate-limit-unavailable`, `about:blank` |

401 means only "your credential is dead". A permission problem is always a 403 or a hidden 404, never a 401, so a valid session is never told to sign in again.

Each operation's possible types are listed in its API reference page.

## Retrying

- **Creates are idempotent by id.** Send the same client-minted id again and you get the existing row, not a duplicate.
- **Appends carry the version you read.** If someone else changed the record meanwhile, you get a 409. Read again and decide; nothing is merged silently.
- **503** always carries `Retry-After`. Wait that many seconds.

## Rate limits

Every request is counted, per person (or per address when unauthenticated), and some operations also spend a narrower bucket. Most responses carry:

| Header | Meaning |
| --- | --- |
| `X-RateLimit-Limit` | the bucket's limit for the window |
| `X-RateLimit-Remaining` | requests left in the window |
| `X-RateLimit-Reset` | seconds until the window resets |

When a bucket is exhausted, the API answers `429` with type `rate-limited` and a `Retry-After` header in seconds. Wait that long before sending again.

Requests that involve one-time codes, such as signing in or stepping up, are limited more tightly and never carry `X-RateLimit-*` headers.

A list request with `limit` above 200 is not rate-limited but refused with `422 invalid-input`. Page through results with `cursor` instead.
