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

# Errors and idempotency

# Error Handling, Idempotency, and Pagination

## Error Envelope

Every error response uses a consistent JSON envelope:

```json theme={null}
{
  "error": {
    "code": "idempotency_key_required",
    "message": "a valid Idempotency-Key header is required"
  }
}
```

Clients should branch programmatically on `error.code` and display `error.message` for diagnostics only.

| HTTP | Code | Meaning & Recommended Action |
| - | - | - |
| `400` | `validation_error` | Request body, path UUID, `limit` (1–100), or `cursor` is invalid. Fix input before retrying. |
| `400` | `idempotency_key_required` | Missing or oversized (`> 255` chars) `Idempotency-Key` header on a write endpoint. |
| `401` | `unauthenticated` | Missing, invalid, expired, or revoked `X-API-Key` or session token. |
| `403` | `insufficient_scope` | Credential lacks the required permission scope for this route. |
| `404` | `not_found` | Resource does not exist in the authenticated tenant. |
| `409` | `idempotency_key_reused` | Same `Idempotency-Key` was sent with a different method, path, or request body. Generate a new key. |
| `409` | `request_in_progress` | Original request with this `Idempotency-Key` is still executing. Retry with backoff using the same key. |
| `409` | `conflict` | Duplicate unique resource (e.g. duplicate wallet or provider transaction ID). |
| `429` | `rate_limited` | Tenant or IP token bucket exhausted. Respect `Retry-After` and retry with backoff. |

## Idempotency Semantics

All state-changing resource endpoints (`POST /v1/organisations`, `POST /v1/api-keys`, `POST /v1/agents`, `PATCH /v1/agents/:id`, wallets, credentials, events, authorizations, verify, revoke, and financial instructions/reconcile) require an `Idempotency-Key` header.

* Attexra hashes `(method, route, requestBody)` and binds it to `(scope, key_hash)` in PostgreSQL.
* Retrying the **exact same request** with the same `Idempotency-Key` returns the original status code and JSON body without re-executing the write.
* Reusing an `Idempotency-Key` for a **different payload or endpoint** fails with `409 idempotency_key_reused`.
* Interactive session routes (`/v1/auth/register`, `/v1/auth/login`, `/v1/auth/logout`) do not require `Idempotency-Key` because they manage session cookies.

## Deterministic Authorization Reason Codes

`POST /v1/authorizations/verify` evaluates grants deny-by-default and returns HTTP `200` with an auditable `decisionId`, `outcome` (`allow`, `deny`, `require_approval`, or `indeterminate`), and `reasonCode`:

* `within_scope` (`allow`)
* `approval_required` (`require_approval`)
* `invalid_grant` (`deny`) — invalid signature, unknown `kid`, or wrong tenant
* `grant_revoked_or_unknown` (`deny`)
* `grant_expired` (`deny`)
* `scope_mismatch` (`deny`) — `action` or `resource` mismatch
* `recipient_mismatch` (`deny`)
* `asset_mismatch` (`deny`)
* `invalid_amount` / `amount_exceeds_limit` (`deny`)

## Cursor Pagination

Collection endpoints (`GET /v1/agents`, `GET /v1/agents/:id/events`, `GET /v1/events`, `GET /v1/authorizations`, `GET /v1/authorizations/decisions`, `GET /v1/financial/instructions`, `GET /v1/api-keys`) accept:

* `limit`: `1` to `100` (default `50`)
* `cursor`: opaque cursor returned in `nextCursor` from the previous response

When `nextCursor` is omitted, you have reached the end of the collection.


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