Swap.io Agent API · x402

TreasuryGuard

An autonomous rebalancer that pays per call in USDC.
No API key. No subscription. It only pays when it actually trades.

Storyboard / mockup. Prices are as listed at hermes.swap.io/v1/info on 2026-11-13; the safety-check price is illustrative.
The situation

A small DAO treasury: 60% SOL / 40% USDC

Rule: if the mix drifts more than 5 points from target, rebalance with one swap.

Reality: that happens a few times a month. Most hours, nothing happens.

The usual way: sign up, store an API key on a server, pay a monthly plan even in the idle weeks.

For an agent that is spun up only when needed, that is a key to leak and a bill for doing nothing.

Trigger

Drift detected: SOL is now 67.2% of the treasury

TreasuryGuard
USDC wallet only
Pre-trade
safety check
Swap.io
quote
Swap.io
build-tx

Plan: sell ~7.2 points of SOL into USDC. Three paid calls, each one settled on the spot.

Step 1 · pay for a safety check before trading
GET /v1/token-safety?mint=EPjF…Dt1v (example provider) ← HTTP 402 Payment Required price: $0.01 USDC payTo: provider wallet → agent signs a USDC payment and retries with the X-PAYMENT header ← HTTP 200 { "mintAuthority": "checked", "freezeAuthority": "checked", "verdict": "ok" } X-PAYMENT-RESPONSE: settlement tx hash · no account, no key

Before moving treasury funds, the bot buys one answer from a verification API, for this trade only.

Step 2 · ask Swap.io for a quote
POST https://hermes.swap.io/v1/swap/quote { input: SOL 3.1, output: USDC, slippageBps: 50, userAddress: treasury } ← HTTP 402 Payment Required { scheme: "exact", network: "solana", asset: USDC, maxAmountRequired: "3000" } = $0.003 → x402 client pays 0.003 USDC and retries automatically ← HTTP 200 { quotes: [ … ranked … ], bestQuote } + X-PAYMENT-RESPONSE (tx hash)

The 402 tells the agent the exact price, token and network. The agent pays and gets the answer in the same loop.

Step 3 · build the swap transaction
POST https://hermes.swap.io/v1/swap/build-tx { providerQuote: bestQuote.providerQuote } ← HTTP 402 maxAmountRequired: "3000" = $0.003 → pay 0.003 USDC · retry ← HTTP 200 { unsigned transaction } agent signs with the treasury key, broadcasts via any Solana RPC, logs the Solscan link

Quotes are short-lived, so the bot builds and sends right away. The rebalance is done.

What it cost in x402 API fees
CallPaid via x402
Safety check (illustrative)$0.010
Swap.io quote (hermes.swap.io/v1/info, 2026-11-13)$0.003
Swap.io build-tx (hermes.swap.io/v1/info, 2026-11-13)$0.003
Per rebalance~$0.016 in x402 API fees
An idle month$0/mo in idle API subscription fees

API fees only: excludes swap LP fees and slippage, Solana network fees, and bot hosting.

Why x402 beats API keys and subscriptions here

No long-lived API credential to leak (agent wallet signing keys still require scoped custody).

Pay only when trading. Idle weeks cost nothing.

Budgets in code. Cap spend per call and per day in the agent, before it signs.

Disposable agents. Spin one up for one rebalance and throw it away, with no signup flow.

The x402 loop, once more

request → 402 → pay USDC → 200

TreasuryGuard: a treasury that rebalances itself and pays cents only when it trades.

Swap.io Agent API: hermes.swap.io · docs.swap.io/developer-tools/agent-api-x402 · x402.org · @swapdotio @Superteam
0:00 / 1:30
Pacta ↗