API/API

Run it locally

These examples run the self-serve API on your machine against Sui testnet, on port 8790.

Start the server#

From the repository root, with dependencies installed (npm ci):

Shell
SUI_NETWORK=testnet \
SELF_SERVE_DEPLOYMENT=deployments/testnet-selfserve.json \
npx tsx services/selfserve/serve.ts

The container image runs the same command on Node.js 24.

  • SUI_NETWORK=testnet is required for the testnet deployment: without it the server targets a local network and refuses to start, because the chain does not match the deployment.
  • PORT changes the port.
  • Locally the server listens on 127.0.0.1 only.

On first start the server creates its operator key in its local key folder; the operator pays gas for every transaction, so send its address some testnet SUI. The address is the sponsor field of GET /v1/config. A key whose address holds mainnet funds is refused.

The server keeps its state, including the admin token, in its data directory. The server prints its data directory when it starts: self-serve (data <directory>) on http://127.0.0.1:8790. A hosted server takes its admin token from SELF_SERVE_ADMIN_TOKEN, at least 32 characters, and its data directory from SELF_SERVE_DATA_DIR.

1. Check it is up#

Shell
curl -s http://127.0.0.1:8790/healthz
# {"ok":true}
curl -s http://127.0.0.1:8790/v1/config

2. Sign in#

Shell
curl -s -X POST http://127.0.0.1:8790/v1/auth/challenge \
  -H "Content-Type: application/json" -d "{\"address\": \"$ADDR\"}"

Sign the returned message as a Sui personal message with the key for $ADDR (see Authentication), then:

Shell
curl -s -X POST http://127.0.0.1:8790/v1/auth/session \
  -H "Content-Type: application/json" \
  -d "{\"address\": \"$ADDR\", \"message\": $MESSAGE_JSON, \"signature\": \"$SIG\"}"
export TOKEN=…   # the "token" field

$MESSAGE_JSON is the message as a JSON string, exactly as returned, newlines included.

3. Create an agent and read it back#

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"}'

curl -s http://127.0.0.1:8790/v1/agents -H "Authorization: Bearer $TOKEN"

4. Quote a loan#

Shell
curl -s -X POST http://127.0.0.1:8790/v1/borrow/quote \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"collateral": "30", "amount": "5"}'

From here, follow Agent transactions to set the agent up, or Borrow transactions to borrow from your own wallet.