API/Endpoints

Agents

Routes for creating, reading and running hosted agents. All need a session. Routes under /v1/agents/:id answer only the agent's owner, the address that created it; any other session gets 404 NO_SUCH_AGENT.

The agent object#

FieldTypeNotes
idstringa- and 16 hex digits.
ownerstringYour address.
namestring
sidelender or borrowerSet by the preset.
presetstringsteady, yield, refinancer, taker, switcher or shopper.
addressstringThe agent's own Sui address.
treasuryId, ownerCapId, agentCapIdstring or nullSet after create lands. For a borrower, these are the SUI treasury's.
cashobject or nullBorrowers only: the cash treasury and its caps.
capExpiresAtMsnumber or nullWhen the agent's rules end.
mandateobject or nullLenders: the form last applied on chain, when and with which digest.
borrowobject or nullBorrowers: the same for the borrower form.
revokedboolean
selfRuntrue or absentA self-run agent: the server holds no key for it and never launches it.
statussetup, ready or revokedready once rules are applied.
createdAt, updatedAtstringISO time.

The agent's key is never returned.

List agents#

GET/v1/agents→ { ok, agents: Agent[] }

Oldest first.

Create an agent#

POST/v1/agents→ 201 { ok, agent }

This creates the agent and its key; nothing is on chain until you sign create.

FieldTypeNotes
namestringLowercase letters, digits and dashes, starting with a letter or digit, up to 63 characters.
presetstringA lender or borrower style.
ErrorStatus
BAD_NAME400
BAD_PRESET400
AGENT_LIMIT429 — you already have the maximum number of agents.
Shell
curl -s -X POST http://127.0.0.1:8790/v1/agents \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"name": "my-lender", "preset": "steady"}'

Preview a lender's rules#

POST/v1/mandate/preview

With { form } → { ok, sentence, chain }, or 400 BAD_FORM with an errors list of { field, message }. Nothing is signed.

The lender form:

FieldTypeRule
namestringAs above.
presetstringsteady, yield or refinancer.
totalBudgetdecimal stringAbove zero, at most the budget limit (100 USDC on testnet).
minLoan, maxLoandecimal stringAbove zero; min ≤ max ≤ totalBudget.
minRateBpsinteger0 to 99,999.
maxLtvBpsinteger1 up to the market's borrow limit.
termsDaysinteger[]One or more of 1, 7, 30.
expiresAtMsintegerIn the future and within 30 days.
aiModebooleanMust be off: AI mode is not available.

chain holds what will be written on chain: totalCap, minFill, maxFill, minRateBps, maxDurationMs, takerKind, takers, maxLtvBps, capExpiresAtMs.

The borrower form is not this create body. It is the form on POST /v1/agents/:id/tx (create, deposit, rules) and on POST /v1/borrow/preview. Every field:

FieldTypeRequiredDefaultUnitsValidation
namestringyes——^[a-z0-9][a-z0-9-]{0,62}$.
presetstringyes——taker, switcher or shopper. switcher needs a pool. A hosted shopper cannot launch.
collateralstringyes—SUI, ≤ 9 decimalsAbove zero.
amountstringyes—USDC, ≤ 6 decimalsAbove zero, at most 100.
maxRateBpsnumberyes—basis points a yearInteger 1–100000.
repayBeforeHoursnumberyes—hoursInteger 0–720. The on-chain lead is at least 1 hour.
cashFloatstringyes—USDC"0" or positive.
expiresAtMsnumberyes—Unix ms62 minutes to 30 days ahead.
autoTopUpbooleannooff—Boolean when present.
topUpSuistringno"0"SUI"0" or positive.
autoClaimbooleannoon—Boolean when present. Only false turns it off.
JSON
{
  "action": "create",
  "form": {
    "name": "desk-taker",
    "preset": "taker",
    "collateral": "1",
    "amount": "1",
    "maxRateBps": 800,
    "repayBeforeHours": 6,
    "cashFloat": "0.05",
    "expiresAtMs": 1793500000000,
    "autoTopUp": false,
    "topUpSui": "0.1",
    "autoClaim": true
  }
}

Set expiresAtMs to a real time in that window. The same object is what EsseyAgent.borrowFromOffer and borrowFromPool run under, once GET /v1/agent/setup is ready: collateral leaves the SUI treasury, the USDC lands in the cash treasury, and repay spends the cash treasury. The calls are on Agent transactions.

Get an agent#

GET/v1/agents/:id
FieldWhat it is
agentThe agent object.
runner{desired, status, ticks, lastTickAt, lastError, killed} or null if never launched.
balances{treasury} for a lender; {treasury (SUI), cash (USDC), allowance} for a borrower; base units.
balances.allowanceBorrowers: {total, remaining} as strings in USDC base units. total is what your last signed rules allowed; remaining is what the chain has left (treasury::borrow_allowance_of). Null before the borrow rules are set.
warningsWhat needs your attention now (below).
withdrawWarningsBorrowers: the repay warnings you would get if you withdrew all the cash.

Runner status is one of running, paused, stopped, killed, limited or blocked.

WarningSideMeaning
REPAY_UNDERFUNDEDborrowerThe cash treasury will not cover a repay by its deadline; includes shortfall and deadlineMs.
RULES_BLOCK_REPAYborrowerThe agent's cash rules end too soon or allow too little per draw to repay.
NEAR_LIQUIDATIONborrowerA loan nears its safety line and auto top-up is off or short; includes suiNeeded.
LOAN_UNDERWATERlenderA loan it made is past its safety line.

Launch, pause, stop#

POST/v1/agents/:id/launch

, /pause, /stop → { ok, runner }. Stop also cancels the agent's standing offers.

Launch is refused with 409 and one of:

ErrorWhen
REVOKEDThe agent was revoked.
SELF_RUNA self-run agent runs on its own machine; the server does not launch it.
ROOM_NEEDS_PASSKEYA shopper cannot be hosted: only your passkey can open its room's bids.
NOT_READYRules not applied yet.
NOT_FUNDEDThe treasury is empty (a borrower's SUI treasury).
KILL_SWITCH_ONThe operator stopped all agents.
CANNOT_START: <reason>The agent failed to start.

Settings#

POST/v1/agents/:id/settings

— hosted borrowers only.

FieldType
autoTopUpboolean, optional
autoClaimboolean, optional

Returns { ok, agent, runner }; a running agent restarts on the new settings. Errors: NOT_READY (409), BAD_SETTING (400) when a value is not a boolean or nothing is set.

Loans#

GET/v1/agents/:id/loans→ { ok, loans }

For a lender, the loans it made; for a borrower, the loans whose deed its SUI treasury holds. Each item is:

FieldNotes
idThe loan object id. Kept for older clients.
loanIdThe same id. GET /v1/borrow/loans already names the field loanId.
principalLoan-coin units, decimal string.
rateBpsThe offer's rate, or the pool rate the summary recorded.
collateralCollateral units, decimal string.
stateopen, or a closed state such as repaid, liquidated, defaulted.
maturityMsWhen an offer loan matures. 0 on a pool loan.
dueAtMsWhen a default can be collected. For a borrower this is maturityMs.
claimableLender: the loan is open, past due, and collectable. Borrower: closed with collateral left to claim.

Activity#

GET/v1/agents/:id/activity→ { ok, items, more }

On-chain events for the agent's treasury merged with the agent's own decisions, the newest 200; more is true when older ones exist. Each item is {at, source: "chain" | "runner", kind, text, digest}.