API/Endpoints

Self-run agents

TESTNET

Routes for an agent that runs on its own machine with its own key (bring your own agent). The agent signs in with that key; the owner, signed in with a passkey or any Sui wallet key, claims the agent's setup code and creates its account. The SDK wraps both sides: EsseyService for the agent, EsseyOwner for the owner (Approve from a wallet key).

An agent session and an owner session never open each other's routes: an agent token on an owner route, or an owner token on an agent route, gets 401 NO_SESSION.

Agent sign-in#

POST/v1/agent/challenge

{address} → {ok, message, expiresAtMs}, then POST /v1/agent/session {address, message, signature} → {ok, token, …}. The same two calls as Authentication, with a message of its own ("… agent wants you to sign in …"), so an owner challenge cannot be replayed here. Challenges are limited to 10 per minute per IP, counted apart from owner challenges.

Start a setup#

POST/v1/agent/setup

{side} → 201 {ok, code, side, expiresAtMs}. side is lender or borrower. The code is 32 hex digits, works once and expires after 15 minutes. Starting a new setup deletes this agent's unclaimed ones.

ErrorStatusWhen
BAD_SIDE400side is not lender or borrower.
DENIED403The address is on the operator's deny list.
AGENT_EXISTS409An agent record already exists for this address.
TRY_LATER429More than 5 setups in an hour from this address.

Read the setup#

GET/v1/agent/setup→ {ok, setup}

Where setup is null or:

FieldWhat it is
statewaiting, expired, claimed, ready or revoked.
sidelender or borrower.
expiresAtMsWhen the code expires.
owner, agentIdSet once claimed.
accountOnce ready: {treasuryId, agentCapId}, and cash: {treasuryId, capId} for a borrower.
capExpiresAtMsWhen the agent's rules end.

ready means the owner's create has landed and the rules are on chain. account is null while state is claimed. After POST /v1/byo/claim, poll this GET (or EsseyService.setup(), which is this GET) until state is ready. That is where treasuryId and agentCapId come from. A borrower also reads account.cash.treasuryId and account.cash.capId.

The borrower create form, sent by the owner as POST /v1/agents/:id/tx with { action: "create", form }. There is no top-level amount.

FieldTypeRequiredDefaultUnitsValidation
namestringyes——^[a-z0-9][a-z0-9-]{0,62}$.
presetstringyes——taker, switcher or shopper. switcher needs a pool.
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,
    "topUpSui": "0.1"
  }
}

autoTopUp and autoClaim are omitted here, so top-up is off and claim is on. Replace expiresAtMs with a time inside the window.

From the agent key, once setup.state is ready:

TypeScript
const agent = await EsseyAgent.start({
  chain,
  deployment,
  signer: agentKey,
  account: setup.account, // treasuryId, agentCapId, cash: { treasuryId, capId }
  gas: "address-balance",
});
const SUI = 1_000_000_000n;
const USDC = 1_000_000n;
await agent.borrowFromOffer(offerId, 1n * SUI, 1n * USDC); // SUI treasury out, cash treasury in
await agent.borrowFromPool(1n * SUI, 1n * USDC); // NO_POOL when there is no pool
await agent.repay(loanId); // owed leaves the cash treasury

EsseyOwner is the owner's wallet-key client for claim and create. See Approve from a wallet key.

Peek and claim (owner session)#

POST/v1/byo/peek

{code} → {ok, address, side, expiresAtMs}. Shows which agent the code is for, without spending it. Compare address with the address the agent showed you.

POST/v1/byo/claim

{code, name, preset} → 201 {ok, agent}. Spends the code and creates the agent record for that address, owned by your session. The preset must match the setup's side. Then create the account with POST /v1/agents/:id/tx and action: "create" (Agent transactions).

ErrorStatusWhen
BAD_CODE400Not 32 hex digits.
WRONG_SIDE400A lender preset for a borrower setup, or the other way round (claim only).
NO_SUCH_SETUP404Unknown, or already claimed.
SETUP_EXPIRED410Older than 15 minutes.
TRY_LATER429More than 20 peeks and claims in a minute from your address.

A claim can also return the agent-creation errors of POST /v1/agents.

POST/v1/agent/sponsor

{bytes, signature} → {ok, digest}. The agent builds a transaction with the operator (selfRun.sponsor in GET /v1/config) as gas owner, a budget of at most selfRun.gasBudgetMax, signs it and sends it here; the operator co-signs and executes it. Only what the hosted agents' lending lane would sponsor is accepted. EsseyService.sponsored(client, tx, config) does all of this.

ErrorStatusWhen
BAD_BODY400bytes or signature missing or not base64.
NOT_A_SELF_RUN_AGENT403No self-run agent for this address.
SENDER_NOT_SESSION403The transaction's sender is not the signed-in agent.
KEYS_NOT_SEPARATE, OWNER_CAP_PUBLIC, OWNER_CAP_UNVERIFIABLE403The agent's OwnerCap is not with its owner.
SPONSOR_REFUSED403Outside the lending lane; message says why.
NOT_READY409The account is not set up yet.
TRY_LATER429More than 20 a minute.
DAILY_SPONSOR_LIMIT429More than 200 a day.
TX_FAILED502The chain refused it; digest when it landed.

Membership credential#

POST/v1/agent/credential

{commitment} → {ok, credential}: the dregg membership credential for the agent's own commitment, issued the same way as the owner's POST /v1/private/credential. Fields, errors and limits are in Private flows & credentials.