Command line and agents / Agents
Agent quick start
The calls an AI agent makes to buy BTC, in order, over plain HTTP or with the command line's --json. An order is typed data the agent's wallet signs, so no person needs to click anything, and the API key cannot move funds. Everything here runs in the sandbox, where nothing real moves.
| # | Call | Gives |
|---|---|---|
| 1 | POST /sandbox/keys | A test key, with no sign-up. Once: keep it |
| 2 | GET /price | What an amount gets now. Nothing reserved |
| 3 | GET /quote | The order for this wallet and address, with steps. Valid for 60 seconds |
| 4 | Sign each signature step, then POST /orders | The orderId |
| 5 | GET /status?orderId=… | state, until it ends |
Get a key once
One IP address can get five test keys an hour, so an agent should get one and reuse it, not get one per run.
export BASE=https://openapi.maxy.co/v1 export MAXY_API_KEY=$(curl -s -X POST "$BASE/sandbox/keys" | jq -r .secretKey)
Price, quote, sign, status
The agent pays with USDC on Base: it signs and sends no transaction. The wallet is a throwaway one here; live, it is the agent's own. The Bitcoin address is a public test address, for a test key only.
H="x-maxy-key: $MAXY_API_KEY" TEST_WALLET_KEY=$(cast wallet new --json | jq -r '.[0].private_key') WALLET=$(cast wallet address --private-key "$TEST_WALLET_KEY") curl -sG -H "$H" "$BASE/price" --data-urlencode "from=USDC on base" -d to=BTC -d amount=20 | jq -c '{toAmount, liquidityAvailable}' curl -sG -H "$H" "$BASE/quote" --data-urlencode "from=USDC on base" -d to=BTC -d amount=20 \ -d fromAddress="$WALLET" -d toAddress=bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 > quote.json jq -e '.sandbox == true' quote.json > /dev/null || { echo 'This sample is for a test key (mxk_test_…).' >&2; exit 1; } jq -c '{quoteId, issues}' quote.json SIGS='{}' for ID in $(jq -r '.steps[]? | select(.kind == "signature") | .id' quote.json); do SIG=$(cast wallet sign --private-key "$TEST_WALLET_KEY" --data "$(jq -c --arg id "$ID" '.steps[] | select(.id == $id) | .typedData' quote.json)") SIGS=$(echo "$SIGS" | jq -c --arg id "$ID" --arg sig "$SIG" '. + {($id): $sig}') done ORDER_ID=$(curl -s -X POST "$BASE/orders" -H "$H" -H "content-type: application/json" \ -d "$(jq -c --argjson sigs "$SIGS" '{order: .order, signatures: $sigs}' quote.json)" | jq -r .orderId) until curl -s -H "$H" "$BASE/status?orderId=$ORDER_ID&chainId=8453" > status.json && jq -e '.isComplete or .state == "refundable" or .error' status.json > /dev/null; do sleep 2 done jq -c '{state, btcTxId, error}' status.json
In the sandbox the order reads pending, then in_progress, then completed, in about 20 seconds. Paying with ETH adds one escrow transaction and POST /orders/submit: Place the order.
With the command line
The same order with npx -p maxy-labs maxy, once the SDK is installed (Command line). MAXY_WALLET_KEY gives the command line a wallet without storing it: here a throwaway one; live, the agent's own. With --json every command prints one JSON object (order watch: one line per change): swap prints it once the order is placed, with orderId and next, the command that follows the order.
export MAXY_WALLET_KEY=$(cast wallet new --json | jq -r '.[0].private_key') npx -p maxy-labs maxy price 20 usdc base --json ORDER_ID=$(npx -p maxy-labs maxy swap 20 usdc base to btc --from MAXY_WALLET_KEY \ --to bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 --yes --json | jq -r .orderId) npx -p maxy-labs maxy order watch "$ORDER_ID" --json
What each answer means
| The agent reads | It means | The agent does |
|---|---|---|
state: pending or in_progress | A solver is committing or paying | Poll again in 2 seconds |
state: completed | The BTC is sent: btcTxId | Record btcTxId, and stop |
state: refundable | No solver filled in time | GET /orders/{id}/refund, and send its transaction from the wallet |
state: cancelled, expired, refunded | Ended, nothing paid out | Stop. Quote again if still wanted |
state: failed | See rawStatus | Stop, and send Maxy the orderId and requestId |
issues.orderCap, order_cap_exceeded | Over the key's cap | Order less |
liquidityAvailable: false | Cannot fill this size now | A smaller amount, or later |
quote_expired | Over 60 seconds since the quote | Quote again, sign again |
429, rate_limited | Over the rate limit | Wait Retry-After seconds |
retryable: true | The same call may work later | Retry it as is: the same signed order returns the same orderId |
Which key an agent gets, and what each can do: For AI agents.