The Killer Combo
x402 payments are USDC transfers. Session keys on CHIPI wallets authorize transfers without requiring the owner key each time.
This makes x402 + sessions ideal for:
- AI agent autonomous API consumption
- Streaming data feeds (pay-per-query)
- Backend automation (server-to-server payments)
- Mobile apps with “subscribe for X hours” UX
React Implementation
How It Works Under the Hood
- Session creation: Generate a temporary keypair, encrypt private key with user’s PIN
- Session registration: Register the session public key on the wallet contract (one owner signature)
- Session constraint:
allowedEntrypoints: ["transfer"]restricts the session totransfercalls. The whitelist is not tied to a contract, so it allowstransferon every token the wallet holds. Cap amounts per token with a spending policy. Function names need 14.13.1 or later; on earlier versions pass the selector (hash.getSelectorFromName("transfer")) - x402 payment: When a 402 is received, the hook uses
executeTransactionWithSession()instead ofexecuteTransaction()— the session key signs automatically
Node.js Backend Automation
For server-side automation where you want to consume paid APIs:Verify a payment the agent sent itself (14.14.0+)
When the paying agent sends the USDC transfer with its own session key (executeTransactionWithSession) and gives you the transaction hash, no facilitator sits in between. A hash is not a payment: check the receipt with SessionTxVerifier before serving the request.
agentWallet from the caller’s authenticated identity, not the request: hashes are public, so an unauthenticated from lets anyone who sees the transaction claim it first. It accepts the payment only if the transaction succeeded, a Transfer event from token moved at least minAmount from from to to, and the hash was never accepted before. Failures come back as REVERTED, TRANSFER_NOT_FOUND, AMOUNT_TOO_LOW or ALREADY_USED; a check that fails does not consume the hash. It throws only when the receipt cannot be read in time, so retry those. X402Facilitator is unchanged. See Agent with a session key and a passkey for the full flow.
Pay for Chipi’s AI API from the session (14.15.0+)
Chipi’s ownPOST /v1/ai/think sells decisions over x402 when your credits are short. sdk.ai.think(params, { payWithSession }) is the buyer side of the pattern above, done for you: it pays the 402 offer with a session-signed USDC transfer, checks the receipt with SessionTxVerifier before sending X-PAYMENT, and refuses before paying when the price is above your maxAmount. The paying wallet must belong to the same organization as the sk_; from 14.15.1 the SDK checks that with the API before paying (X402_PAYER_NOT_IN_ORG). See DeFi Intelligence.
On-Chain Spending Limits
Session keys alone don’t enforce dollar limits —maxCalls caps the number of transactions, not the amount. For real budget control, use Spending Policies:
success: true with nothing moved, so the seller (and a careful buyer) checks for the Transfer, which is what SessionTxVerifier and sdk.ai.think’s payWithSession do.
Spending policies require CHIPI v33 wallets. See the full guide: Spending Policies.
Three Layers of Protection
For production x402 deployments, use all three.
Security Considerations
Session Scope
Always restrict session keys to the minimum required permissions:- Per-request limit:
maxPerCallenforced on-chain ($0.10 per API call) - Session window limit:
maxPerWindowenforced on-chain ($10 per 6 hours) - Transaction count limit:
maxCalls: 100enforced on-chain - Client-side guard:
maxPaymentAmount: "0.10"(early rejection, saves gas)
Session Expiry Fallback
If the session expires during a payment, the hook falls back to requiring the owner’s signature (wallet popup / biometrics / PIN):Best Practices
- Set spending limits: Always configure
maxPaymentAmountand sessionmaxCalls - Whitelist merchants: Use
allowedRecipientswhen possible - Monitor payments: Use
onPaymentCompletecallback for logging/analytics - Short sessions: Prefer shorter session durations with renewal over long-lived sessions
- Transfer-only: Always set
allowedEntrypoints: ["transfer"]for x402 sessions, plus a USDC spending policy: the whitelist allowstransferon any token
