Reference

Errors

Handle API error responses using stable error codes and human-readable messages.

Errors are JSON with a stable machine-readable errorCode and a human errorMessage. Branch on errorCode — not on the message text, and not on the HTTP status alone.

Error shape#

Every module returns the same envelope. errorCode is the contract: it is stable across versions and safe to switch on. errorMessage is for your logs and may be reworded at any time. details is optional and rarely populated — treat it as opaque free text for humans, never as a parseable structure. Note that the OpenAPI contract still carries a legacy example showing a play.numscript.org link; nothing in the current Ledger emits a URL there, so do not build a link out of it.

FieldTypeNotes
errorCodestring, enumStable machine-readable code. The value you branch on.
errorMessagestringHuman-readable explanation. Not stable — do not parse it.
detailsstringOptional, usually absent. Where set, it is the underlying error text — not a URL and not structured. Omitted on COMPILATION_FAILED.
json
{
  "errorCode": "INSUFFICIENT_FUND",
  "errorMessage": "account had insufficient funds: user:john:wallet, USD/2"
}

Common error codes#

INSUFFICIENT_FUND and CONFLICT are the two worth explicit handling — the first blocks a transaction from posting, the second signals the operation already landed.

CodeStatusWhat it means
VALIDATION400The request is malformed — unknown filter field, both postings and script, bad date. Fix the call.
INSUFFICIENT_FUND400A source account cannot cover a posting. Either fund it, or pass force if a negative balance is legitimate for that account.
COMPILATION_FAILED400Numscript did not compile. The compiler diagnostics are in errorMessage; details is not set on this error.
CONFLICT409The reference is already taken in this ledger. Usually means the transaction already succeeded — fetch it rather than retrying.
NOT_FOUND404The ledger, transaction or account does not exist. Note that reading a never-used account address returns a zero balance, not a 404.

What to retry#

Retry 429 and 5xx with exponential backoff. A 4xx is otherwise deterministic — the request will fail identically, so fix it rather than repeating it.

401 is the one exception. Tokens expire (one hour by default), and a missing or expired token is reported the same way as an invalid one — 401 with no body detail — so the status alone does not tell the two apart. Refresh the token once and replay the request; if the replay is still 401, the credentials themselves are wrong and further attempts will not help. Cap it at a single refresh-and-retry per request so bad credentials cannot become a refresh loop.

The SDKs handle the token cache but not the replay: on a 401 the client-credentials hook discards the cached session so the next call fetches a fresh token, and it acquires a token before a request when none is cached. The failed request itself is still returned to you, so the single retry above is yours to make.

Idempotency-Key is what makes retrying an ambiguous write safe, but it is narrower than "Ledger and Wallets". It is honored on the Ledger v2 data-plane writes (create and revert transaction, transaction and account metadata write/delete, create schema) and on the Wallets write endpoints, which forward it to the Ledger. Where it is honored, send the same key on every retry: if the original call landed, the Ledger replays that response, so retrying a timed-out POST is safe.

It is not honored on Ledger v2 admin and control operations (ledger creation, _bulk, ledger-level metadata, buckets, exporters, pipelines, log import/export), on any Ledger v1 endpoint, or on Payments, Reconciliation and Auth. Retrying one of those after a timeout can duplicate the effect, so read current state first and retry only if the write did not land.

Webhooks is a special case that cuts the other way: its delivery replay endpoints require Idempotency-Key rather than merely accepting it, and cache the replay result for 24 hours, so a replay retried with the same key returns the original outcome instead of replaying twice. Reusing that key for a different replay is a conflict. No other Webhooks endpoint takes the header. See Conventions for the per-endpoint breakdown, and treat the endpoint's own entry in the API reference as authoritative.

ConditionRetryHow
401onceRefresh the token, then replay once. A second 401 means invalid credentials, not expiry.
429yesHonor Retry-After; back off exponentially with jitter.
500, 502, 503, 504, endpoint honors Idempotency-KeyyesRetry with backoff and the same key.
500, 502, 503, 504, endpoint does notyesRetry with backoff. Read first if the operation may have landed.
timeout / connection reset, endpoint honors Idempotency-KeyyesRetry with the same key — that is precisely what it is for.
timeout / connection reset, endpoint does notmaybeCheck current state first; retry only if the write did not land.
403 or any other 4xxnoDeterministic. Fix the request — a 403 needs a token with the right scope, not a retry.