# Errors and conventions

Shared behavior for authentication, writes, pagination, and failures.

## Idempotency

Send a unique `Idempotency-Key` header with the requests that accept it. Reusing a key with a different payload returns a conflict. These operations accept the header:

- [`POST` Upload a statement import](https://tetri.app/docs/api/v1/imports#post-imports)
- [`POST` Confirm a statement import](https://tetri.app/docs/api/v1/imports#post-imports-by-id-confirm)
- [`POST` Create a transaction template](https://tetri.app/docs/api/v1/transaction-templates#post-transaction-templates)
- [`POST` Create a transaction](https://tetri.app/docs/api/v1/transactions#post-transactions)
- [`PATCH` Update a transaction](https://tetri.app/docs/api/v1/transactions#patch-transactions-by-id)
- [`DELETE` Delete a transaction](https://tetri.app/docs/api/v1/transactions#delete-transactions-by-id)

## Common errors

Every error response has the same JSON body: `statusCode`, a stable machine-readable `code` (for example `VALIDATION_FAILED` or `PROGRAMMATIC_SCOPE_REQUIRED`), an English `message` meant for logs, optional structured `details` (for `VALIDATION_FAILED`, `details.errors` maps each invalid field to the failed constraints) and `request_id`. Branch on `code`, never on `message`.

Example `400` body:

```
{
  "statusCode": 400,
  "code": "PROGRAMMATIC_PAGINATION_MODE_CONFLICT",
  "message": "after and page are mutually exclusive",
  "details": {
    "errors": {
      "limit": [
        "max"
      ]
    }
  },
  "request_id": "8cf64dcc-0f73-4f8d-a845-3d80c1040475"
}
```

**Deprecated code spellings.** Codes are SCREAMING\_SNAKE. A few codes that `v1` returned before this convention keep their original lowercase or dotted spelling on `v1` (for example `budget.notFound` or `transaction.revisionConflict`) so existing integrations keep working; they are deprecated and switch to SCREAMING\_SNAKE (`BUDGET_NOT_FOUND`, `ENTITY_VERSION_CONFLICT`) in the next API version.

## Status codes

- `400` Request parameters or payload failed validation. Inspect \`code\` and \`details\`.
- `401` The personal access token is missing, invalid, expired, or revoked.
- `403` The token lacks the required scope or no longer has workspace access.
- `404` The resource does not exist in the token workspace or is not visible to this API.
- `409` The idempotency key was reused with a different request or the resource state conflicts.
- `413` The uploaded statement exceeds the 10 MiB limit.
- `422` The payload is syntactically valid but violates a domain constraint.
- `429` The credential exceeded its request rate limit.

## Pagination

Collection endpoints return metadata alongside items. Each one documents the pagination parameters it accepts:

- `page` (number) — accepted by Wallets, Budgets, Transactions, Goals, Recurring rules
- `limit` (number) — accepted by Wallets, Budgets, Transactions, Goals, Imports, Recurring rules
- `after` (string) — accepted by Imports, Transactions
