AiFinPay is token-free. Agents pay in real assets — USDC, USDT, SOL, MATIC — settled on Solana and Polygon mainnet. There is no AiFinPay token to buy or hold.
mSECCO is a non-transferable internal accounting unit, not a tradable asset.Install
The package ships as ESM (
"type": "module"), so the top-level await used in the snippets below works directly in a .mjs / .ts module.Your first paid call
The fastest path: generate a fresh agent, fund it, and callagent.pay(url). The Ed25519 / EVM keypair is generated locally with tweetnacl and never leaves your process — the SDK only sends a one-time signature to authenticate.
1
Generate an agent and print its address
2
Fund the address
Send a few cents of the appropriate asset to the printed address. You can poll until funds arrive:
3
Pay and get the response
agent.pay() handles the whole 402 dance for you: it reads the challenge, settles the payment on-chain, retries with the proof, and returns the upstream response.The capability layer: AiFinPayAgent
agent.pay(url) is perfect when you already know the endpoint. When you’d rather ask for a capability (“search this”, “run this inference”) and let AiFinPay route to the best live provider, use the unified AiFinPayAgent. It manages both a Solana and an EVM identity and settles each call atomically on-chain.
Discover providers
discover() browses the live provider catalog. Filter by category ("search", "inference", "image", "speech") and/or free-text q. Each entry carries live connectivity so you can rank client-side too.
DiscoveredProvider: slug, name, price_usd, availability ("available" | "recruiting"), status ("live" | "down" | "unknown"), latency_ms, and an optional transparent score.
Pick the single best provider
pickProvider() asks the gateway for the best available provider in a category, ranked by price, latency, liveness, and on-chain trust. Cap the candidate set with maxPriceUsd.
ProviderUnknownError when nothing payable matches.
One-line web search
webSearch() is the highest-level call: it picks the best search provider, pays it, and returns the response. It resolves to null only if a budget cap is hit in "skip" mode (see below).
Call a provider by name
If you already know which provider you want, skip routing and call it directly.call() resolves the provider, picks a chain, settles on-chain, and retries with payment proof.
call() accepts { provider, body, cost?, chain?, bridgeUrl?, method?, timeoutMs?, signal? } and returns Promise<Response | null>.
Budget caps
Cap per-call and daily spend at construction time, or update later withsetBudget(). With on_limit_exceeded: "skip", a call that would breach a cap resolves to null instead of paying — useful in loops where you’d rather drop a task than overspend.
Check balances across chains
balance() returns a USD-normalised snapshot across both chains, plus rolling 24h spend and the active caps.
The snapshot also reports
msecco_balance per chain. mSECCO are non-transferable usage credits earned by paying agents — they are not tradable and cannot be withdrawn.Loading an existing keypair
To reuse an agent identity across runs, load it instead of generating a new one.- Agent (simple)
- AiFinPayAgent (unified)
How a payment settles
You see one function call. Under the hood, for every paid request the SDK:- Sends the request unauthenticated → the bridge replies with HTTP 402 and a JSON challenge listing chain, asset, recipient, amount and
nonce. - Settles on-chain — either an Ed25519-signed Solana challenge or a Polygon
B2BSplitter.payMatic()transaction, depending on what the server accepts. The split is atomic (merchant / treasury / IP-creator) and no custodian ever holds the funds. - Retries the original request with the payment proof header (e.g.
x-tx-hash+x-order-idon Polygon, orx-solana-txon Solana). - Returns the upstream response once the bridge has verified settlement on-chain.
Next steps
x402 discovery doc
The machine-readable discovery document agents read to find payable endpoints.
GitHub Issues
Questions, bugs, and feature requests for the SDK.