x402BatchSettlement contract, and PayAI relays every on-chain leg and pays the gas.
PayAI serves
batch-settlement on Base mainnet (eip155:8453) and Base Sepolia (eip155:84532) at https://facilitator.payai.network. Access is public: no PayAI account or API key is needed when you run your own receiver authorizer. With a PayAI API key you can instead let PayAI hold the authorizer key (see section 2), and pay for settlement legs with credits after the free allowance.How it works
- Deposit. The customer signs a USDC authorization (EIP-3009, or Permit2 for other ERC-20s) that funds a channel identified by its immutable config: payer, receiver, receiver authorizer, token, withdraw delay and a salt. PayAI submits the deposit; the customer pays no gas.
- Vouchers. Each request carries a voucher with a cumulative ceiling: everything charged so far plus this request’s maximum. Your server verifies the signature locally in a few milliseconds and charges the actual amount, from zero up to the ceiling. Nothing touches the chain.
- Claim. On your schedule, your server sends the latest voucher per channel to PayAI, which submits one
claimWithSignaturetransaction covering up to 25 channels. - Sweep. A
settletransaction transfers everything claimed for your receiver and token to your wallet in one transfer. - Refund or withdraw. Your server can cooperatively refund a customer’s unused balance at any time; the customer can always start a timed withdrawal (one to 24 hours under PayAI’s policy) as a unilateral fallback.
1. Install the upstream SDK
PayAI runs the merged x402 Foundation implementation. Use the published packages; no PayAI-specific build is required:BatchSettlementEvmScheme from @x402/evm/batch-settlement/server on your server and the same-named class from @x402/evm/batch-settlement/client on the customer side. The reference server and client live in the x402 repository under examples/typescript/servers/batch-settlement and examples/typescript/clients/batch-settlement.
2. Choose a receiver authorizer
The receiver authorizer is the key that signs claims and refunds for your channels. You have two options. The address is part of every channel’s immutable config, so pick one before you open channels.Option A: your own key (default, no account needed)
Option B: PayAI holds the authorizer (API key required)
If you would rather not operate a signing key, PayAI can sign claims and refunds for you. PayAI advertises its authorizer address in/supported only to authenticated callers, so every facilitator call from your server must carry a PayAI JWT (how to mint one), including the /supported call the SDK makes at startup. Each JWT must carry a unique jti: PayAI consumes it on /verify and /settle, so mint a fresh token per call.
- The first authenticated deposit
/verifyfor a channel reserves it for your account; the deposit/settlefrom the same account binds it. First writer wins. - Claims, refunds and voucher or refund verifies on that channel must come from your account. Requests from any other account, or without a JWT, are refused. Sweeps stay public because they only pay the channel’s receiver.
- Delegated legs bill like any authenticated leg: the free allowance first, then credits, at the same per-leg prices.
- Lock-in. PayAI’s authorizer address is hashed into every channel id. To move those channels to another facilitator, claim outstanding vouchers and refund the remaining balances first.
- Fallback. If PayAI is unavailable, the channel’s receiver can still call
claimandrefundon the contract directly, but only if the receiver is an EOA or a contract able to make those calls. Use Option A if yourpayTois a routing contract. - Rotation. If PayAI rotates its advertised address, channels on the old address keep working, but one claim batch cannot mix channels from two authorizers; drain old channels before your channel manager mixes them. Restart your server after a rotation so it reads the new address.
3. Run the channel manager
Claims and sweeps happen when your server asks for them. Run the exported channel manager against the same durable storage:4. Policy and limits
ReadbatchPolicy from GET /supported for the live values; these are the defaults:
Top-ups to an existing channel are not bound by the initial-deposit range. The upstream server announces a
minDeposit hint of ten times the route price by default, which for a $0.01 route is exactly PayAI’s 0.10 USDC floor; raise the route’s extra.minDeposit if your customers should fund more per channel.
5. What PayAI bills
Every on-chain leg PayAI relays for you is priced at the observed gas plus 30 percent: deposit, claim, sweep and refund. Vouchers are free; they never reach PayAI. Without an API key, legs draw on the public free-tier allowance for yourpayTo address and are refused when it is exhausted. With a merchant API key they are billed as credits. There are no privileged legs: a refused claim or sweep never strands funds, because claimWithSignature, settle and refundWithSignature are permissionless on the contract and you can relay them yourself.
Observed on Base mainnet: a deposit costs about 140,000 gas, a single-channel claim about 77,000, a sweep about 57,000 and a refund about 95,000. At Base fees today that is well under a cent per leg.
Recovery
Retry the exact payload after a timeout, asettlement_pending answer, or a lost response. Deposits, claims and refunds are content-addressed: an identical retry returns the recorded outcome, and if the original transaction is still unconfirmed PayAI reconciles it from its receipt rather than broadcasting again. A claim that is no longer strictly increasing is refused with batch_claim_not_increasing, which means the earlier claim landed; reconcile against the channel’s on-chain totalClaimed.
Sweeps are different: a settle request sweeps whatever is owed now, so it has no durable identity. A second sweep while one is in flight returns 409 duplicate_settlement. A sweep with nothing left to move returns nothing_to_settle, and when a recent sweep for that receiver and token is known the response carries extra.lastSweep with its transaction and amount. A settlement_pending sweep answered with an empty transaction hash means PayAI was still waiting for the receipt; retry after a minute.

