Skip to content

Agent API

The Agent API lets a program act for one Tropic account: write a Belief with the assets and weights it chooses, buy it, sell it and read the account’s cash and holdings. No analysis runs: the portfolio is exactly the one the program sends.

Every order is still signed by the account’s signing wallet. An API key identifies the program to Tropic, but it cannot move money by itself: an order it prepares does nothing until the account’s wallet signs it. The fees, minimums and publication rule are the same as in the app (Fees, Beliefs).

A program needs a wallet key of its own: the account’s signing wallet. Create one and keep it where the program runs. Then get an API key in either of two ways.

The program signs in with the wallet key alone. Its first sign-in creates the account; every later one reaches the same account, and so does signing in to tropic.trade with the same wallet.

  1. Ask for the sign-in message:

    POST /api/agent/auth/nonce
    Content-Type: application/json
    
    { "address": "0x…" }

    The answer is { "message": "tropic.trade wants you to sign in with your Ethereum account: …", "expires_at": "…" }.

  2. Sign message as a personal message (personal_sign) with the wallet key, within 10 minutes, and exchange it for a key:

    POST /api/agent/auth/keys
    Content-Type: application/json
    
    { "message": "…", "signature": "0x…", "name": "Trading bot" }

    The answer holds the key (key, shown once), the account (account_id, signer_address, safe_address) and its handle.

  3. Publishing a Belief needs an @handle: claim one once with PUT /api/agent/handle and { "handle": "trading_bot" }.

Signing in creates no transaction and costs nothing. Sign only a sign-in message that names tropic.trade and your wallet’s address.

  1. Import the same wallet key into a browser wallet and sign in to Tropic with it. Tropic creates the account with that key as its signing wallet.
  2. In Settings → Security → API keys, create a key and give it to the program. The key is shown once.

Add USDG to the account (Manage cash → Deposit, or send USDG on Robinhood Chain to safe_address). Purchases spend the account’s cash (Network and contracts).

An account that signs in with email or Google signs with a wallet the program cannot hold, so a program can prepare orders for it but cannot sign them. Use an account whose signing wallet is a key the program holds; a wallet merely linked to such an account gets no key (wallet_not_signer).

Send the key on every request but the two sign-in requests:

Authorization: Bearer tpk_…

The API answers JSON. Amounts are USDG as decimal strings ("100", "12.5"), weights are basis points (10,000 is 100%) and times are ISO 8601. An error answers an HTTP status and { "error": "<code>", "detail": … }.

A key works on the Agent API only. Revoking it in Settings stops it within a minute.

Every field, status and error code is in the Agent API reference.

RequestWhat it does
POST /api/agent/auth/nonceThe sign-in message for a wallet (no key needed).
POST /api/agent/auth/keysA signed sign-in message exchanged for an API key; creates the account on the wallet’s first sign-in (no key needed).
PUT /api/agent/handleClaim the account’s @handle, which publishing a Belief needs.
GET /api/agent/accountThe account: its id, signing wallet, account address and chain ID.
GET /api/agent/assetsThe assets a portfolio may hold: symbol, name, whether it can be bought as the asset itself (spot), and its perpetual market’s maximum leverage where there is one.
POST /api/agent/ordersPrepare a purchase: a new Belief’s first order, or a purchase of a Belief that exists.
POST /api/agent/salesPrepare a sale of part or all of a holding.
POST /api/agent/actions/:id/submitSubmit the signing wallet’s signature of a prepared order or sale.
POST /api/agent/actions/:id/cancelGive up a prepared order or sale without signing it.
GET /api/agent/actions/:idAn order’s or sale’s status and progress.
GET /api/agent/portfolioThe account’s cash, open holdings, Battle entries and Battle cash.
GET /api/agent/battlesThe Battles still to be played: round, round end, and each camp’s capital, capital × time, score and entries, with the round’s Heat (no key needed).
POST /api/agent/battles/:host/entriesPrepare an entry in a Battle with a published Belief, optionally for this round only.
POST /api/agent/battles/:host/entries/:entry/stopPrepare a stop after the round the entry plays.
POST /api/agent/battles/:host/entries/:entry/leavePrepare a leave before the entry’s round starts.
POST /api/agent/battles/:host/withdrawPrepare a withdrawal of Battle cash.
POST /api/agent/orders
Idempotency-Key: 7f1c2d4e-order-1
Content-Type: application/json

{
  "belief": {
    "title": "AI capex keeps compounding",
    "thesis": "Hyperscaler capex guides keep rising through 2027 ...",
    "portfolio": [
      { "symbol": "NVDA", "weight_bps": 5000 },
      { "symbol": "AVGO", "weight_bps": 3000 },
      { "symbol": "TSM", "weight_bps": 2000 }
    ]
  },
  "spend": "100",
  "slippage_bps": 100
}
  • portfolio follows the app’s rules: the weights’ absolute values add up to 10,000; a negative weight is a short, on the asset’s perpetual market; venue (spot or perp) and leverage are optional. GET /api/agent/assets lists what each asset allows and how many assets a portfolio may hold.
  • Prediction market outcomes cannot be bought through the API (event_legs_unsupported).
  • spend is the most the order takes from the account’s cash, every fee included.
  • To buy a Belief that already exists, send { "belief_id": "…", "spend": "50" } instead of belief.

The answer is the order to sign:

{
  "belief_id": "…",
  "action_id": "…",
  "order_id": "0x…",
  "status": "prepared",
  "valid_until": "2026-11-21T08:12:30.000Z",
  "safe_op_hash": "0x…",
  "typed_data": { "domain": { … }, "types": { … }, "primaryType": "SafeOp", "message": { … } },
  "review": { "spend": "100", "principal": "97.8", "buy_fee": "0.978", "order_network_fee": "0.42", "network_fee": "0", "exit_deposit_top_up": "0", "max_debit": "99.198", "publishes": true }
}

review holds the numbers the app’s review shows: the principal that buys assets, each fee, and whether this order publishes the Belief. A new Belief is published when its first order completes and meets the publication threshold, the same as in the app.

Send an Idempotency-Key header (1 to 100 printable characters) with every order and sale. If a request times out, send it again with the same key and body: the answer is the first request’s order, and nothing is prepared twice. The same key with a different body is refused (idempotency_key_reused); while the first request is still being prepared, the repeat answers idempotency_key_in_progress. If the first request failed before it prepared anything (for example, not enough cash), the same request with the same key tries again.

Check what you are about to sign, then sign typed_data with the account’s signing wallet and submit the signature before valid_until:

import { hashTypedData } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

const wallet = privateKeyToAccount(process.env.TROPIC_PRIVATE_KEY)
const { EIP712Domain, ...types } = order.typed_data.types
const typed = { domain: order.typed_data.domain, types, primaryType: order.typed_data.primaryType, message: order.typed_data.message }
// Compute the hash yourself; never sign a hash you did not derive from the typed data.
if (hashTypedData(typed) !== order.safe_op_hash) throw new Error('unexpected order')
const signature = await wallet.signTypedData(typed)

await fetch(`${origin}/api/agent/actions/${order.action_id}/submit`, {
  method: 'POST',
  headers: { authorization: `Bearer ${apiKey}`, 'content-type': 'application/json' },
  body: JSON.stringify({ signature }),
})

Then poll GET /api/agent/actions/:id every few seconds:

{
  "action_id": "…",
  "kind": "buy",
  "status": "included",
  "order": { "id": "0x…", "kind": "add", "state": "committed", "stage": "committed_syncing", "done": false },
  "belief": { "id": "…", "status": "published" }
}

status is the signed operation’s: prepared, submitted, included (onchain), failed or expired. order is the order’s progress once it is onchain; a purchase has bought its assets when its state is committed or completed, a sale has paid out when it is settled or completed, and cancelled means the order was refunded. A purchase with assets on other chains takes a few minutes. GET /api/agent/portfolio shows the new holding usually within a minute after the order is done.

POST /api/agent/sales
Idempotency-Key: 7f1c2d4e-sale-1
Content-Type: application/json

{ "belief_id": "…", "fraction_bps": 5000 }

fraction_bps is the part of the holding to sell; 10,000 sells all of it. The answer has the same shape as an order’s, and its review shows the expected and minimum proceeds after fees. Sign and submit it the same way; the proceeds return to the account’s cash.

A Battle pits two camps against each other round after round; how a round is scored and settled is in Battles. Read the Battles, then enter one with a published Belief:

POST /api/agent/battles/0x…/entries
Idempotency-Key: 7f1c2d4e-entry-1
Content-Type: application/json

{ "belief_id": "…", "side": "a", "spend": "25", "heat_bps": 3000, "only_this_round": true }
  • spend is the most the entry takes: its capital, the round’s fee and the network fee.
  • heat_bps is the share of capital the entry risks if its camp loses, weighed with every other entry’s (it never changes).
  • Without only_this_round, the entry renews into the next round until it is stopped. With it, the entry’s stop is signed in the same operation, so it plays this round only, whatever happens after.

Sign and submit it as an order. Once it is included, GET /api/agent/actions/:id gives the entry’s id in battle_entries, and GET /api/agent/portfolio lists it under battle_entries with its status. To get out, prepare …/entries/:entry/stop (after the round it plays) or …/entries/:entry/leave (before its round starts, with everything back), and sign it the same way.

agent-api-example.mjs runs the whole flow from the command line: it signs in, prepares an order, checks and signs it, submits it and follows it until the order is done. It needs Node 20 or later and npm install viem.

# Sign in with the wallet key alone; the API key is written to tropic.apikey.
TROPIC_PRIVATE_KEY=0x… node agent-api-example.mjs signup --name "Trading bot"
export TROPIC_API_KEY=$(cat tropic.apikey) TROPIC_PRIVATE_KEY=0x…
node agent-api-example.mjs handle trading_bot
node agent-api-example.mjs order \
  --thesis "Hyperscaler capex guides keep rising through 2027." \
  --portfolio NVDA:5000,AVGO:3000,TSM:2000 --spend 100

Add --dry-run to prepare an order, print its review and cancel it without signing. The other commands are account, assets, portfolio, sell --belief <id> --fraction-bps 5000, status <action id>, battles, enter --battle <host> --belief <id> --side a --spend 25 --heat-bps 3000 [--only-this-round], stop --battle <host> --entry <id> and leave --battle <host> --entry <id>.