AI agents and treasury automation
You want software to do routine treasury work: notice that the dollar buffer is low, propose converting surplus pesos, move money between your accounts, pay a supplier you already pay every month. You do not want that software to be able to empty the treasury, approve its own requests, or act without a trace.
This guide shows how to run such an agent on the Business API. It is for automation and finance teams, and for the developer who builds the agent. The "agent" can be a scheduled job, a rules engine or a language model: the platform treats them all the same, and nothing here depends on a particular AI vendor or model.
The outcome:
- The agent has its own identity, a service account that can read and propose, or execute within limits, and nothing more.
- Policy rules on the platform, not just checks inside the agent, hold anything large for a person to approve and refuse anything above a ceiling.
- Every write carries an idempotency key, so a retry cannot pay twice.
- The audit trail names the agent as the initiator and the person as the approver.
- One call switches the agent off.
A working example: treasury-agent (download the zip) keeps a USD buffer topped up from surplus ARS, with a decision log and a mock mode you can run without credentials.
How it works
The agent proposes, the platform decides and executes, and people approve what the policy holds.
sequenceDiagram
participant Agent as Agent (service account)
participant API as Business API
participant Policy as Policy rules
participant Person as Approver (console)
Agent->>API: Read balances, price and conversion preview
Agent->>API: POST /conversions with Idempotency-Key
API->>Policy: Evaluate active rules for this conversion
Policy-->>API: Require one approval
API-->>Agent: 202, status pending_approval, approval_ref
Agent->>Agent: Record the approval id and stop
API-->>Person: Case appears under Approvals
Person->>API: Approve, with MFA step-up
API->>API: Execute the conversion as the agent
API-->>Agent: Event operations.conversion.settled.v1
Agent->>API: GET the conversion, report the result
- The agent reads balances, an indicative price and a conversion preview. None of these move money.
- It submits the conversion with an
Idempotency-Key. - The platform evaluates the active policy rules for the operation.
- A rule requires a person's approval, so the conversion stops at
pending_approvaland the response carries anapproval_ref. - The agent records the approval reference and stops. It does not resubmit.
- The approval case appears in the console under Approvals.
- A person who is allowed to decide approves it, with an MFA step-up.
- The platform executes the conversion under the agent's identity.
- The platform publishes
operations.conversion.settled.v1(orfailed). - The agent reads the conversion and reports the result.
Small operations under the rule's threshold skip steps 4 to 7 and execute
straight away. Operations a deny rule matches are refused at step 3 with
422.
Before you start
- Sandbox access. An enterprise, an account holding funds, and a person
who can create service accounts, roles and policy rules. Those setup rights
(
service_accounts.create,roles.create,role_assignments.create,policies.create,policies.manage) belong to that person, never to the agent. - Worth reading first: Identity, Access, Policies and approvals, Operations and Idempotency and concurrency.
- The treasury calls themselves (balances, conversions, transfers, payouts, reconciliation) are explained in Smart treasury and international payments. This page adds what changes when software, not a person, makes them.
1. Give the agent its own identity
Create one service account per agent. Never let an agent use a person's credentials or share a key with another integration: the audit trail can only be as precise as the identity behind each call. In the console, service accounts are under API Keys.
Bundle the capabilities into a role, then provision the account with that role
in one call. Each capability below is the x-required-capability of the
operation the agent calls.
A read-and-propose agent
It watches and suggests; a person executes the suggestion in the console.
| Capability | Lets the agent call |
|---|---|
accounts.read | GET /master-accounts/{master_account_id}/balances, GET /client-accounts/{client_account_id}/balances, GET /master-accounts, GET /client-accounts |
conversions.read | GET /conversions, GET /conversions/{conversion_id} |
internal_transfers.read | GET /internal-transfers, GET /internal-transfers/{internal_transfer_id} |
withdrawals.read | GET /withdrawals, GET /withdrawals/{withdrawal_id} |
deposits.read | GET /deposits, GET /deposits/{deposit_id} |
withdrawal_destinations.read | GET /withdrawal-destinations |
events.read | GET /events, GET /events/{event_id} |
approvals.read | GET /approvals, GET /approvals/{approval_id} |
Prices and previews need no capability: GET /prices/indicative,
GET /prices/assets, POST /fee-previews, POST /conversions/preview and
GET /conversion-pairs. The account you ask about must still be inside the
service account's scope. GET /me/capabilities tells the agent what it holds.
An agent that executes within limits
The same list, plus the create capabilities for the operations it may start:
| Capability | Lets the agent call |
|---|---|
conversions.create | POST /conversions |
internal_transfers.create | POST /internal-transfers |
withdrawals.create | POST /withdrawals |
Add only the ones it needs: an agent that only converts gets
conversions.create and no payout capability. Add conversions.manage,
internal_transfers.manage or withdrawals.manage only if it should cancel
its own operations.
withdrawals.create means "can pay any crypto address". POST /withdrawals
accepts an inline crypto destination with a network as well as a
registered destination_id, and no policy condition matches on the
destination. Withholding withdrawal_destinations.create does not keep the
agent on registered destinations. Either do not grant withdrawals.create,
or hold every withdrawal the agent starts for a person: a require_approval
rule with an initiator condition and no amount condition (step 2).
Never grant an agent
| Capability | Why not |
|---|---|
approvals.decide | It could take part in approving its own proposals. The platform does not count a service account as an approver anyway. |
policies.create, policies.manage | It could retire the rule that holds it. |
roles.create, roles.manage, role_assignments.create, role_assignments.manage | It could grant itself more. |
service_accounts.create, service_accounts.manage, service_accounts.rotate_secret | It could mint new credentials or undo its own revocation. |
withdrawal_destinations.create, withdrawal_destinations.manage | It could add or re-enable a payout destination of its choosing. Withholding them is not enough on its own: see withdrawals.create above. |
Create the role and the account
A person with the setup rights creates the role:
Then provisions the service account with it. Assign the role at the narrowest
scope that covers the accounts the agent manages. For an agent that runs only
your master account, grant it at the enterprise with scope_propagation
self, as below. For an agent that serves one connected account, grant it at
that connected account (API: clients/<id>).
The 201 response carries client_id, client_secret, principal_ref
(service-accounts/<id>) and role_assignments. Three things to check:
role_assignment_errorsmust be empty. The account is created even when a grant fails, and the response is still201.client_secretappears only in this response. Store it in your secret manager, never in the agent's prompt, code or logs. A retry with the same key returns the account without the secret.client_secret_ttl_seconds(minimum 60) bounds how long a leaked secret works. A person rotates it withPOST /service-accounts/{service_account_id}/rotate-secret.
The agent then gets its token with the client-credentials grant; see Authentication. See Provision service account with roles for every field.
2. Put the guardrails on the platform
Limits inside the agent help, but the agent's own code or model can be wrong.
Rules on the platform hold even then. Write them for the agent's service
account specifically with an initiator condition.
This rule holds every conversion the agent submits that is worth 5,000 USD or more until one person approves it:
A rule is created as a draft and does nothing until it is activated with the
etag from the response:
Add a second rule for a hard ceiling: the same conditions with operator
gt, a higher threshold, and a decision of kind deny with a reason.
Write the same pair for internal_transfer if the agent may start those. For
withdrawal, drop the amount condition: a require_approval rule with only
the initiator condition holds every withdrawal the agent starts, because a
withdrawal can go to any crypto address.
How the platform applies rules:
- Most restrictive wins. When several active rules match,
denybeatsrequire_approval, which beatsallow. - A rule that cannot be evaluated does not pass silently. If a condition
needs a value the platform cannot compute at that moment (for example the USD
equivalent of the amount), a
denyorrequire_approvalrule that would otherwise match asks for an approval instead. - Conditions per operation type.
conversion:amount_threshold,asset,asset_class,conversion_asset_class_pair,initiator.internal_transfer:amount_threshold,asset,asset_class,direction,initiator.withdrawal:amount_threshold,asset,asset_class,initiator. No condition matches on the withdrawal destination, so a person approving each withdrawal is what keeps payouts on known destinations. - A refusal is an error, not a status. A deny rule answers the create
request with
422,codenot_admissible,data.sourcepolicyanddata.reasonPOLICY_BREACH(orLIMIT_EXCEEDED), and no operation snapshot comes back.
The console shows rules under Policies. See Create policy rule.
When the agent's operation needs approval
The create request still succeeds, with 202. The operation's status is
pending_approval and approval_ref holds approval_id, reason_code (the
rule's reason) and expires_at. The agent should record the approval id,
report it, and stop. Submitting again would only create a second held
operation, so keep one open proposal at a time.
The approval case, GET /approvals/{approval_id} (needs approvals.read),
shows its status (pending, approved, rejected, cancelled or
expired), requirement_snapshot.required_human_approvals,
collected_human_approvals and initiated_by, the agent. A case the policy
raises expires 24 hours after it opens unless someone decides.
Who can decide. A person, never a service account. They need
approvals.decide with a grant covering the operation's scope, the approver
role if the rule names one, and they cannot be the initiator when
initiator_cannot_approve is true.
GET /approvals/{approval_id}/eligible-approvers lists them. The decision is
POST /approvals/{approval_id}/approve or
POST /approvals/{approval_id}/reject, made in the console under Approvals
or by the person's own client. Both can ask for an MFA step-up
(401 insufficient_user_authentication). One rejection closes the case
whatever the quorum.
What happens next. On approval the operation continues and executes under
the agent's identity. The platform resolves the agent's rights again at that
moment, so a role revoked in the meantime is not used. On rejection or expiry
the operation ends failed, with failure_reason APPROVAL_REJECTED or
APPROVAL_EXPIRED. The events operations.conversion.pending_approval.v1 and
operations.conversion.approved.v1, followed by .settled.v1 or .failed.v1,
let the agent follow without polling. The same events exist for withdrawals
and internal transfers.
Action tokens and human step-up
When a person's token submits a conversion, a withdrawal or an external
settlement conversion, the request also needs an X-Action-Token header. The
person's client gets the token from POST /action-tokens with
{"action": "conversion.create", "command": <the same body>}. The token is
bound to that person and that exact command, lasts five minutes and works once,
and issuing it can require an MFA step-up.
Service accounts are exempt and cannot get one: the request is refused, with
401 from the MFA check or with 403. So:
- An agent on its own service account sends no action token. The policy rule is its brake.
- For "the agent drafts, a person confirms", let the agent prepare the exact request body and have the person's session issue the action token for it and submit it. The token proves the person approved those exact amounts, and the operation is attributed to the person. See Issue action token.
3. What the agent reads
| Question | Call | Notes |
|---|---|---|
| How much is there? | GET /master-accounts/{master_account_id}/balances, GET /client-accounts/{client_account_id}/balances | Plan with available; held is reserved for operations in flight. |
| What does it cost right now? | GET /prices/indicative | Non-binding. account_ref is required; the price is the one that account would get. |
| What fees apply? | POST /fee-previews | Non-binding; reserves nothing. |
| What would this conversion return? | POST /conversions/preview | binding is always false; check execution_min_source_amount. |
| Which pairs exist? | GET /conversion-pairs | Global catalog, not a per-account guarantee. |
| What happened? | GET /conversions, GET /internal-transfers, GET /withdrawals, GET /deposits | One status list for all families. |
| Where may money go? | GET /withdrawal-destinations | The registered destinations. The API does not limit the agent to them; an approval rule on its withdrawals does. |
| What changed? | GET /events | Or webhooks a person sets up; see Events and webhooks. |
| What waits for a person? | GET /approvals with scope_ref and status=pending | |
| What may I do? | GET /me/capabilities | Check it at start-up; refuse to run with rights from the list above. |
For example, the price of covering an 8,000 USD shortfall from pesos:
from_amount in the answer is what it would cost. Then preview that amount
with POST /conversions/preview to see the fees; the request and response are
in Smart treasury and international payments.
4. What the agent does
Every write follows the same pattern: preview, choose an idempotency key, write the key down, submit, follow the operation, report.
Convert.
Move funds between your own accounts.
Pay a destination that is already registered. The agent sends the destination's id; it never sends bank details or an address.
For a crypto payout the stored destination is destination_id with rail
crypto. POST /withdrawals also accepts a one-time inline destination for
crypto; an agent should never use it, and nothing on the platform stops it
from doing so except an approval rule on its withdrawals (step 2).
Idempotency. Use one key per decision, for example derived from the
agent's own decision id, and store it before sending. On a timeout, 429,
502 or 503, send the same body with the same key: the platform returns the
first answer instead of creating a second operation. The answer is kept for 24
hours. A different body with a used key returns 409 idempotency_conflict.
After an operation has failed, a new attempt needs a new key.
Handle the outcome
| Answer | Meaning | What the agent does |
|---|---|---|
202, status settled | Executed. | Report the figures: target_amount, applied_rate, fee_summary. |
202, status requested, admissible (conversion, internal transfer) or executing (withdrawal) | Accepted, still moving. | Follow the operation or its events until a final status. |
status executed or ledger_visible | In the enum, but the platform does not set either today. | Treat it as not final: report it and keep reading. |
202, status pending_approval | Held by a policy rule. | Record approval_ref.approval_id, report, stop. Do not resubmit. |
202, status pending_compliance | Held for a compliance review. | Wait; the platform resumes it. |
status failed or cancelled | Ended without moving the principal. | Read failure_reason; do not retry blindly. |
422 not_admissible, data.source policy | Refused by a deny rule. | Report it; a person must change the request or the rule. |
403 | Missing capability or account outside scope. | Stop and report; do not look for another way. |
401 principal_revoked | The service account was revoked or suspended. | Stop for good. |
429, 502, 503, or no answer | Temporary. | Retry with the same key and backoff. |
Final statuses are settled, partially_settled, failed and cancelled.
Treat every other status as not final, as the
transaction lifecycle
does. See Errors for the error envelope and
Rate limits for backoff.
5. Keep an audit trail
The platform records who did what. The agent records why.
- On every operation,
subject_attribution.authenticated_principalis the agent's service account (kindservice, its id). The same block is on every event the operation publishes. - On the approval case,
initiated_byis the agent anddecision.decided_byis the person who approved or rejected it. - In the audit log,
GET /user-action-audit-entries/search?enterprise_ref=<enterprise_ref>&authenticated_principal=service-accounts/<id>&occurred_from_utc=<from>&occurred_to_utc=<to>returns what the agent initiated (audit.read, a capability for your compliance team, not for the agent). Entries about its operations haveaction_familyfinancial_operation_auditand the operation id incorrelation_id. The decisions on them are entries withaction_familyapproval_decision, whereattribution.initiated_byis the agent,attribution.approved_bythe person, andcorrelation_idthe same operation id. The audit log records requests, holds, decisions, failures and cancellations; settlement itself is in the operation and its events. - Exports for auditors and accounting:
POST /user-action-audit-exports(audit.create_export) andPOST /operations-activity-exports(operations_reports.create_export), incsvorjson. - The agent's own log: for every decision, the inputs it saw, what it proposed and why, the preview, the idempotency key and the operation id. Only the agent knows its reasons; keep them next to the platform's record.
Acting on behalf of a person. If your integration exchanges a person's identity token for an access token (see Identity), the platform records that person as the actor; it does not keep the integration as a separate actor. The person's rights apply, and their money movements need their action token. Use this only when that person is really deciding. An agent acting on its own uses its own service account, so the record says so.
6. Resources for agent builders
| Resource | What it is |
|---|---|
/llms.txt | Index of every docs page with a one-line description. |
/llms-full.txt | All docs pages in one file. |
/llms/<page path>.md | Each page as Markdown, for example this page. |
/openapi.json | The contract. Each operation carries x-required-capability, so you can derive the capability list from the calls your agent makes. |
/openapi-sandbox.json | Adds the sandbox-only simulation routes. |
| Errors, Rate limits, Idempotency | How to branch on failures, back off and retry safely. |
Give a model the documentation and the observation it must decide on, never the credentials or the access token. Keep the API calls in your own code, which applies the limits below to whatever the model returns.
Safety checklist
- Scoped credentials. One service account per agent, a role with only
the capabilities above, assigned at the narrowest scope. None of the
"never grant" capabilities. The secret in a secret manager, with a
bounded
client_secret_ttl_seconds. - Approval thresholds on the platform. A
require_approvalrule with aninitiatorcondition for the agent and an amount threshold, and adenyrule above a hard ceiling, for each operation type it may start. Activated, and tested on sandbox. - Payouts held for a person.
withdrawals.createlets the agent pay any crypto address, becausePOST /withdrawalsaccepts an inlinedestination. Either do not grant it, or activate arequire_approvalrule with aninitiatorcondition and no amount condition for all of the agent's withdrawals. The agent also pays only destinations a person registered (destination_id) and does not holdwithdrawal_destinations.create, but that is its own discipline, not a platform control. - Dry run first. Run with previews only (
POST /conversions/preview,POST /fee-previews,GET /prices/indicative) until its proposals look right. They move nothing and need no capability. - Hard limits in the agent too. Validate every proposal (currency, decimal string, per-operation maximum, reserve to keep) before any call, whatever produced it.
- Idempotency key on every write, stored before sending, reused on retry.
- One open proposal at a time. While an operation is
pending_approval, propose nothing new. - Watch it. Subscribe to the operation events, and review the audit search for the agent's service account regularly.
- Kill switch. A person revokes the service account with
POST /service-accounts/{service_account_id}/revoke(needsservice_accounts.manage). From the next request the agent's calls fail with401 principal_revoked, even with a token that has not expired. Then reject its pending approval cases. To pause rather than stop, revoke its role assignment withPOST /role-assignments/{role_assignment_id}/revoke.
Test it on sandbox
Sandbox-only: Works on sandbox only. These routes return 404 in production. Fund the account with a simulated deposit as in Sandbox testing, then:
- Check that your pair exists for your account:
GET /conversion-pairsand aPOST /conversions/preview. Adjust the agent's currencies if not. - Create the role, the service account and the policy rule above, and activate the rule.
- Run the agent in preview-only mode, then for real with an amount above the
threshold. The conversion stops at
pending_approval. - Approve it in the console under Approvals, signed in as a person who holds the approver role the rule names.
- Revoke the service account and confirm the agent's next call answers
401 principal_revoked.
The treasury-agent example does steps 3 to 5 for you, and its mock mode shows the whole flow without credentials.
Related
- Smart treasury and international payments: the treasury calls in detail.
- Example apps: treasury-agent and the others, each with a mock mode.
- Policies and approvals, Access, Identity.
- Reference: Service accounts, Roles, Policies, Approvals, Audit log.