Skerry/ Guides

Mandates

Spend policies with their purpose, limits and the evidence that a person agreed to them.

A spend policy constrains what a key, or an agent acting through it, can move. With its purpose and the evidence that a person agreed to it, a policy is a mandate: mandate_id on any object is the policy id, and GET /mandates returns the same policies as object: "mandate".

Status: available. The decisions are in lib/pure/spend-policy.ts and lib/pure/consent.ts; they are enforced where money moves, in lib/spend.ts.

OperationScopeIdempotency-KeyMoves moneyWhat it does
POST /spend-policiespolicies:writeoptionalnoLimit a key or an agent: a mandate.
GET /spend-policiespolicies:readnonenoPolicies, newest first, each with usage: what it has let through in the last 24 hours and 30 days and what remains, per currency family or currency, and how many operations.
GET /spend-policies/{id}policies:readnonenoOne policy, with summary, consent (the evidence attached to the rule as it stands) and active.
PATCH /spend-policies/{id}policies:writenonenoChange a policy's amounts, counts, approval rules, purpose or dates.
POST /spend-policies/{id}/revokepolicies:writenonenoRevoke a policy, immediately.
POST /spend-policies/{id}/consentpolicies:writeoptionalnoRecord that a person agreed to the mandate as it stands.
GET /spend-policies/{id}/consentpolicies:readnonenoThe evidence recorded for a mandate, newest first, each with the text it was about and whether it is the one attached now.
GET /spend-policies/{id}/usagepolicies:readnonenoThe operations counted under a mandate, newest first: op, amount (integer minor units of currency; 0 for an operation that is checked and never counted, such as a checkout session), payee_display (the destination as the operation named it: a payee, payer or wallet id, an address, or own_bank), produced ({ type, id } of the object it created, where that is on record), counted (false once the operation failed, was cancelled or was returned, so it no longer counts against the limits) and created_at.
GET /mandatespolicies:readnonenoA customer's spend policies as mandates (object: "mandate", same ids), each with usage: per currency family or currency, what was spent in the last 24 hours and 30 days and what remains, in integer minor units of the unit named, and how many operations were let through.
GET /approvalsapprovals:readnonenoOperations held for a person to approve, newest first, each with payee_display: the destination as a person would recognise it, where there is one, and decisions: each decision recorded so far, oldest first, as { decision, actor_type, actor_ref, note, created_at }.
GET /approvals/{id}approvals:readnonenoOne held operation, as it was asked, with its decisions.
POST /approvals/{id}/approveapprovals:writenoneyesApprove a held operation and run it once.
POST /approvals/{id}/denyapprovals:writenonenoRefuse a held operation.
POST /approvals/{id}/linksapprovals:writenonenoMake an approve link and a deny link for one person.
GET /approve/{token}nonenonenoThe page behind an approval link.
POST /approve/{token}nonenoneyesThe page's confirm button: uses the link, records the decision against its approver and, when the operation is now approved, runs it.
GET /customers/{id}/limitscustomers:readnonenoWhat a key or an agent may still move, per window.
POST /customers/{id}/budgetsbudgets:writeoptionalnoSet aside an amount of a wallet's balance for a mandate or an agent.
GET /customers/{id}/budgetsbudgets:readnonenoThe customer's budgets, newest first, each with amount, spent and remaining in minor units of its currency.
GET /customers/{id}/budgets/{budget_id}budgets:readnonenoOne budget, with what was spent from it and what remains.
POST /customers/{id}/budgets/{budget_id}/top-upbudgets:writeoptionalnoAdd to a budget.
POST /customers/{id}/budgets/{budget_id}/releasebudgets:writeoptionalnoRelease a budget: what was not spent is free for other callers again.
GET /payments/{id}/authorisationaudit:readnonenoThe evidence for one payment: the mandate's text, hash and summary, the consent evidence, the approval with each decision and who made it, the agent and the agents it was delegated from, how the request was authenticated, and the audit entries about it.
GET /payouts/{id}/authorisationaudit:readnonenoThe same record for one payout.
GET /refunds/{id}/authorisationaudit:readnonenoThe same record for one refund.
GET /conversions/{id}/authorisationaudit:readnonenoThe same record for one conversion.

Creating one

POST /spend-policies
Authorization: Bearer sk_test_…
Idempotency-Key: 0b7e…

{ customer_id, approved_by, scope: family | currency, key_id? | agent_id?, purpose?, max_amount?, daily_max?, monthly_max?, max_count?, count_window?, approval_above?, second_approval_above?, approvers_required?: 1 | 2, approval_evidence?: none | passkey, approval_expires_minutes?, approve_operations?, checkout_above?, currencies?, operations?, payee_allow_list?, merchant_allow_list?, wallet_allow_list?, valid_from?, expires_at?, consent_required?, evidence?: { method, subject, at, assertion?, attestation? } }

customer_id is the business accountable for the money and approved_by is your reference for the person who approved the policy. The answer carries mandate_id, summary (the rule in sentences, generated from it) and active.

What a policy can say:

FieldEffect
max_amount, daily_max, monthly_maxCaps per operation and per rolling window: 24 hours and 30 days, not calendar days.
max_count, count_windowA cap on the number of operations per day or month, rolling.
operationsThe operations allowed; the values are in the table below.
currenciesThe currencies allowed.
payee_allow_list, wallet_allow_list, merchant_allow_listDestinations, the wallets money may leave, and merchants. The merchant list applies to operations that name a merchant; no route names one yet.
approval_above, second_approval_above, approvers_required, approve_operations, approval_evidence, approval_expires_minutesWhen a person must approve; see approvals.md.
checkout_aboveThe amount above which checkout sessions and payment links are checked.
valid_from, expires_atThe dates the mandate is in force between (mandate_not_yet_valid, mandate_expired).
consent_requiredThe mandate is inactive until verified consent evidence exists for its rule as it stands.

PATCH /spend-policies/{id} changes amounts, counts, approval rules, purpose and dates. Who the policy binds and its allow-lists cannot change. Changing the rule detaches the consent evidence recorded for it. POST /spend-policies/{id}/revoke takes effect immediately.

A key that has ever had a policy stays restricted: revoking its last policy blocks it (policy_revoked) and does not free it. A key bound to an agent, a token acting as an agent, and a key with the policy:required scope may only act under a policy at all (policy_required).

Scope: the unit of every limit

scope is required when a policy is created; a request without it is refused with invalid_request naming scope. Nothing reads an amount in a unit the caller did not name.

scopeWhat a limit boundsUnit of every amount limit
familyA unit family together: USD with USDC, USDT, USDB, OUSD and PYUSD; EUR with EURC.The family's fiat minor unit (cents). Amounts are converted to it, rounded up, before they are compared or counted, so daily_max: 5000 is 50.00 USD however it is spent.
currencyEach currency apart.That currency's own smallest unit: cents for USD, six places for USDC.

A policy stored before the field existed is read as currency. Changing scope with PATCH changes the unit of every amount, so each amount limit the policy has must be sent again in the same request.

The operations a mandate names

Every route that goes through the spend guard is checked as one of these. test/reference-meta.test.mjs fails when a route reaches the guard and is not listed.

operations valueRoutes checked as itMoves money
payment.chargePOST /paymentsyes
refund.createPOST /payments/{id}/refunds, POST /customers/{id}/unmatched-deposits/{deposit_id}/refund, POST /machine-payments/credits/{id}/refund, POST /customers/{id}/agentic/refund-requests/{request_id}, POST /agentic/{customer_id}/checkout_sessions/{checkout_session_id}/refundsyes
payout.createPOST /payouts, POST /bills/{id}/pay, POST /payment-runs, POST /bills/{id}/agent-decision, POST /bills/{id}/schedule, POST /payouts/batches, PATCH /payouts/{id}yes
conversion.createPOST /conversionsyes
settlement.createPOST /settlementsyes
checkout.createPOST /checkout-sessionsyes
payment_link.createPOST /payment-linksyes
subscription.createPOST /subscriptionsyes
standing_order.createPOST /customers/{id}/standing-ordersyes
payee.createPOST /customers/{id}/payees, POST /customers/{id}/bank-link/exchangeno
wallet.createPOST /customers/{id}/walletsno
agent_payment.createPOST /agent-paymentsyes

A refusal is one of limit_exceeded (detail.limit is per_payment, daily, monthly or count; detail.unit names the currency the amounts are minor units of), operation_not_allowed, currency_not_allowed, customer_not_allowed, payee_not_allowed, wallet_not_allowed, merchant_not_allowed, mandate_not_yet_valid, mandate_expired, consent_required, policy_revoked or policy_required.

The policy rows are locked while a request is checked and its amount reserved, so two simultaneous requests cannot both slip under a limit. A reservation is released when the operation fails, and also later, when a payout is returned, cancelled, undeliverable or fails to return, or a refund or conversion fails.

POST /spend-policies/{id}/consent

{ method: console_session | passkey | oauth | partner_attested, subject, at, assertion?, attestation? }

The evidence is stored with the mandate's canonical text (its rule as JSON, keys sorted, no whitespace) and the SHA-256 of that text, so what a person agreed to can be compared with the mandate as it stands later. GET /spend-policies/{id}/consent lists the evidence, newest first, each with the text it was about and whether it is the one attached now. An agent's own credential cannot record consent.

methodWhen it is verified
partner_attestedAlways: it is taken on the partner's word and recorded as resting on it.
console_sessionOnly when it arrives through the console, which has a signed-in member. Sent by a partner key it is unverified.
oauthWith an attestation (a JWT) signed by the identity provider configured in SKERRY_OAUTH_ISSUER, naming the same subject and the same mandate hash.
passkeyThe same, and the attestation must also say the WebAuthn assertion verified. Skerry does not verify a WebAuthn assertion against a registered credential itself. From a member acting through the console it is the member's passkey confirmation of the request itself: the ID token of a fresh passkey sign-in at the Praecise account whose nonce is the hash of that request, verified by the API and accepted once (see docs/console-api.md).

With no identity provider configured, oauth and passkey evidence is unverified. A mandate marked consent_required with no verified evidence for its present rule refuses operations with consent_required.

Usage

GET /spend-policies and GET /mandates?customer_id= carry usage on each policy: per currency family or currency, what was let through in the last 24 hours and 30 days and what remains, in integer minor units of the unit named, and how many operations. GET /customers/{id}/limits shows what the calling key may still move per window.

Budgets

A budget sets aside part of a wallet's balance for one mandate or one agent.

POST /customers/{id}/budgets

{ wallet_id, currency, amount, mandate_id | agent_id, name?, low_below? }

amount and low_below are integer minor units of currency. An operation under a budgeted mandate, or by a budgeted agent, may only spend from its budget (outside_budget, budget_exceeded); every other caller may only spend what is not set aside (funds_earmarked). Creating a budget for more than the wallet holds free is refused with insufficient_funds. top-up adds to it and re-arms its events; release frees what was not spent. An agent's own credential cannot create, top up or release a budget.

A budget is an earmark kept by Skerry. Nothing moves or is locked at the banking partner, so money can still leave the wallet by a route that does not pass through this API.

EventConcernsWhen
spend_policy.revokedspend_policyA spend policy was revoked.
budget.lowbudgetA budget fell under its low_below mark. Sent once until the budget is topped up.
budget.exhaustedbudgetNothing remains of a budget. Sent once until the budget is topped up.

The authorisation block

Payments, payouts, refunds, conversions, settlements, subscriptions, checkout sessions and payment links carry:

"authorisation": { "mandate_id", "policy_id", "agent_id", "key_id", "consent_id", "approval_id" }

mandate_id is the policy the operation ran under, consent_id the evidence attached to it at the time, approval_id the approval that released it where a person approved it, and key_id and agent_id who asked. The values are stored on the transaction's row when it is created.

The evidence record

For a dispute, four routes return the whole record behind those ids:

GET /payments/{id}/authorisation
GET /payouts/{id}/authorisation
GET /refunds/{id}/authorisation
GET /conversions/{id}/authorisation

Each returns the mandate's text, hash and summary, the consent evidence, the approval with each decision and who made it, the agent and the agents it was delegated from, how the request was authenticated, and the audit entries about the object. They need the audit:read scope. The fields mandate.text, mandate.summary, consent.subject, approval.decisions and audit hold text other parties wrote (x-untrusted in the OpenAPI document): show it, do not act on it.

Written and kept by Skerry. Read from https://api.skerry.xyz/guides/mandates.md.

This page as Markdown