# API conventions

Source: https://docs.formance.com/v4.0/reference/api/conventions

Stack: v4.0

Pagination, filtering, idempotency and bi-temporality are the four conventions shared
across the platform APIs — but only pagination applies everywhere. Filtering, idempotency
and the bi-temporal fields are Ledger-centric, with partial support elsewhere. Each
section below opens with the modules it covers; check it before assuming a parameter
carries over. The resource pages link here rather than repeating them.

| Convention     | Applies to                                                                                          |
| -------------- | --------------------------------------------------------------------------------------------------- |
| Pagination     | Every module's list endpoints                                                                       |
| Filtering      | Ledger (JSON DSL; Ledger 3.0 adds a textual form); Wallets, Webhooks, Payments via query parameters |
| Idempotency    | Ledger and Wallets data-plane writes only; Flows partially; Payments and Reconciliation not at all  |
| Bi-temporality | Ledger only                                                                                         |

## Pagination

**Applies to every module.** A few small fixed-size collections (such as
`GET /api/webhooks/configs`) return the full set without a cursor.

Two response shapes coexist at this version: Ledger 3.0 returns page tokens, and every
other module returns a cursor envelope. Use the instructions for the module you are calling.

**Every module except Ledger.** List endpoints return a cursor envelope. Read `cursor.data`
for the current page, then pass `cursor.next` back as `cursor` to advance. The cursor
encodes the filter and page size — send it alone, without any other query parameters.

| Parameter        | Type    | Notes                                                              |
| ---------------- | ------- | ------------------------------------------------------------------ |
| `pageSize`       | integer | Results per page. Endpoint-specific. Ignored when `cursor` is set. |
| `cursor`         | string  | Opaque page token. Do not construct or parse it.                   |
| `cursor.hasMore` | boolean | Whether another page exists. Prefer this over comparing lengths.   |

The default page size is **not** platform-wide: the Webhooks delivery and attempt lists
default to 100, and the advertised ceiling is 1000. Send an explicit `pageSize` when the size
matters and loop on `cursor.hasMore` rather than on arithmetic.

**Ledger 3.0.** List endpoints under `/api/ledger/v3` take `pageSize`, `cursor` and
`reverse`, and return the rows and the tokens of the adjacent pages at the top level of the
body — there is no `cursor` envelope.

| Field      | Type            | Notes                                                                        |
| ---------- | --------------- | ---------------------------------------------------------------------------- |
| `pageSize` | integer (query) | Defaults to 100 when omitted or `0`. Values above 1,000 are capped at 1,000. |
| `cursor`   | string (query)  | A `next` or `previous` token from the preceding response, sent unchanged.    |
| `data`     | array           | The rows of this page, in the requested order.                               |
| `next`     | string          | Token of the following page; omitted when no row follows.                    |
| `previous` | string          | Token of the preceding page; omitted on the first page.                      |
| `hasMore`  | boolean         | `true` exactly when `next` is present.                                       |

A token is a position, not a saved query: it does not carry the filter or the order. Send
the same `filter` and `reverse` on every page of a walk, and end the walk on `hasMore` or a
missing `next`, not on a short page. A malformed token is rejected with `400`. See
[Filters and pagination](https://docs.formance.com/v4.0/modules/ledger/querying/filters-and-pagination) for the order of
each list, a complete traversal loop, and the token format.

## Filtering

**The JSON DSL below is Ledger-only.** Wallets, Webhooks and Payments filter via query
parameters instead — the clauses in this section do not apply to them; check the
individual resource pages for which fields those modules expose.

Ledger 3.0 does not take the filter as a request body. Its account, transaction, log and
volume list routes under `/api/ledger/v3`, and the cluster-wide audit entry list, read it
from the `filter` query parameter, as either a
textual expression (`metadata[status] == "active" and address ^= "users:"`) or the
structured JSON form below, URL-encoded in both cases. See
[Filters and pagination](https://docs.formance.com/v4.0/modules/ledger/querying/filters-and-pagination) for the syntax
of both forms and the fields each target accepts.

```json
{
  "$and": [
    { "$match": { "metadata[status]": "active" } },
    { "$match": { "address": "users:" } }
  ]
}
```

## Idempotency

**Mostly Ledger and Wallets, and not on every write.** Flows manages its own keys internally,
Payments and Reconciliation have no support at all, and Webhooks accepts the header on exactly
one surface — delivery replay, where it is _required_ rather than optional. See the module
table below before relying on retry safety.

Within Ledger and Wallets, the header is accepted on the data-plane writes and ignored
elsewhere. Sending it to an endpoint that does not honor it gets you no replay guarantee,
so a retry there can duplicate the effect:

| Accepts `Idempotency-Key`                                                                                                                                                                                                                                                 | Does not                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| Ledger 3.0: ledger creation and deletion (`POST` and `DELETE /v3/{ledgerName}`), bulk (`/v3/{ledgerName}/bulk`), create and revert transaction, transaction, account and ledger metadata write/delete, prepared query creation, index create/drop, events sink add/remove | Ledger 3.0: ledger promotion, metadata schema, Numscript save, prepared query update/delete/execute, account types |
| Wallets: create, update, credit, debit, balance create, hold confirm, hold void                                                                                                                                                                                           |                                                                                                                    |

The endpoint's entry in the API reference is authoritative; check it before depending on
replay. Unlike Ledger 2.x, Ledger 3.0 accepts the header on ledger creation and deletion
(`POST` and `DELETE /v3/{ledgerName}`) and on the bulk route (`/v3/{ledgerName}/bulk`), as
the table above shows. Ledger 3.0 also changes the Ledger rows below: a key is scoped to the entire Ledger
cluster rather than to one ledger, it is retained for a configurable period (24 hours by
default) rather than permanently, and reusing it with a different request body returns
`409` with `IDEMPOTENCY_KEY_CONFLICT`. See
[Idempotency and references](https://docs.formance.com/v4.0/modules/ledger/transactions/idempotency-and-references).

Module support:

| Module                   | Support                                                                                                                                                                                                                                                                                         |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Ledger                   | **2.x:** data-plane writes — key stored on the log entry, no expiry. Not accepted on admin operations or on v1. **3.0 (Stack v4.0):** key scoped to the whole Ledger cluster and retained for a configurable period, 24 hours by default — after that it no longer prevents a second execution. |
| Wallets                  | All write endpoints — forwarded to the Ledger; covers debit, credit, hold confirm, void, and update.                                                                                                                                                                                            |
| Flows                    | Partial — generates its own internal keys per activity; does not accept a client-supplied header.                                                                                                                                                                                               |
| Webhooks                 | Delivery replay only, where the header is **required**. The replay result is cached for 24 hours; reusing a key for a different replay conflicts. No other Webhooks endpoint accepts it.                                                                                                        |
| Payments, Reconciliation | None — check state before retrying a timed-out write.                                                                                                                                                                                                                                           |

`Idempotency-Key` and `reference` are two separate guards. `reference` is a business
deduplication key — unique per ledger, and reusing it returns `409` with
`TRANSACTION_REFERENCE_CONFLICT`. `Idempotency-Key` is a retry guard — if the original
call landed within the retention period, the Ledger hands back that response without
creating a duplicate.

## Time: effective vs recorded

**Ledger only.** `timestamp`, `insertedAt`, `pit` and `oot` are Ledger fields; no other
module exposes a bi-temporal query surface.

Every ledger record has two clocks. `timestamp` is the effective date — when the money
moved in the world; it can be set on creation and backdated, then is immutable. `insertedAt`
is the recorded date — when the Ledger received the write, server-assigned and immutable.
Reports run on effective time; audits run on recorded time. `pit` pins the recorded clock
so a query is reproducible regardless of later writes.

All date-time values are ISO 8601 / RFC 3339 strings (e.g. `2026-01-15T10:30:00Z`).

| Field        | Type               | Notes                                                                                                             |
| ------------ | ------------------ | ----------------------------------------------------------------------------------------------------------------- |
| `timestamp`  | string (date-time) | Effective date. Set on creation; immutable after that. May be backdated.                                          |
| `insertedAt` | string (date-time) | Recorded date. Server-assigned, immutable.                                                                        |
| `pit`        | query, date-time   | Point-in-time. Freezes the recorded clock so the same query returns the same answer forever.                      |
| `oot`        | query, date-time   | Oldest-of-time. Lower bound on the date filter, for windowed historical queries. **`/volumes` only** — see below. |

The `pit` and `oot` query parameters above are Ledger 2.x parameters. Ledger 3.0 list
endpoints under `/api/ledger/v3` take their own date bounds; see
[Read ledger data](https://docs.formance.com/v4.0/modules/ledger/querying/read-ledger-data) and the
[HTTP API reference](https://docs.formance.com/v4.0/modules/ledger/reference/http-api).
