BonzAI uses an HTTP 402-inspired payment protocol for P2P inference. Payments are processed on Base (chain ID 8453) in ETH or USDC.
Protocol Overview
The x402 flow follows a challenge-response pattern:
Consumer sends inference request to provider via libp2p
Provider returns 402 Payment Required with amount and address
Consumer sends payment (ETH or signed EIP-712 authorization)
Consumer retries request with payment proof (tx hash)
Provider verifies payment on-chain, processes inference, returns result
Payment Methods
Direct ETH Payment
The simplest flow — consumer sends ETH directly:
Consumer → BonzaiPayment.payDirectETH(provider, service) + msg.value
Direct USDC Payment
Consumer approves and sends USDC:
Pre-Deposited Balance
For faster payments, consumers can pre-deposit funds:
EIP-712 Signed Authorization
For contract-mediated payments with replay protection:
Consumer signs an EIP-712 typed message:
Provider submits the signature to BonzaiPayment.processPayment()
Contract verifies signature, deducts from consumer's deposited balance, distributes funds
Domain: BonzAI x402 version 2, chain ID 8453
On every payment:
Providers set a pricePerToken (price per 1,000 tokens in wei) during registration.
The consumer's cost is calculated as:
Minimum: 100 tokens per request.
If the consumer and provider are the same node (matching peerId), no payment is required. Self-inference is always free.
Replay Protection
On-chain: Each (consumer, nonce) pair can only be used once
Off-chain: Provider maintains a nonce cache in Electron Store (24h TTL, 10K entry cap)
Expiry: Signed payments expire after 5 minutes
Supported Tokens
USDC on Base: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
Last updated