Skip to main content

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

  1. Session creation: Generate a temporary keypair, encrypt private key with user’s PIN
  2. Session registration: Register the session public key on the wallet contract (one owner signature)
  3. Session constraint: allowedEntrypoints: ["transfer"] restricts the session to transfer calls. The whitelist is not tied to a contract, so it allows transfer on 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"))
  4. x402 payment: When a 402 is received, the hook uses executeTransactionWithSession() instead of executeTransaction() — 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.
Take 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 own POST /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:
The contract enforces this automatically: a payment over the per-call limit or the rolling window total is refused by the wallet. Sent through Chipi’s paymaster, the receipt can still say 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:
This creates a comprehensive spending cap:
  • Per-request limit: maxPerCall enforced on-chain ($0.10 per API call)
  • Session window limit: maxPerWindow enforced on-chain ($10 per 6 hours)
  • Transaction count limit: maxCalls: 100 enforced 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

  1. Set spending limits: Always configure maxPaymentAmount and session maxCalls
  2. Whitelist merchants: Use allowedRecipients when possible
  3. Monitor payments: Use onPaymentComplete callback for logging/analytics
  4. Short sessions: Prefer shorter session durations with renewal over long-lived sessions
  5. Transfer-only: Always set allowedEntrypoints: ["transfer"] for x402 sessions, plus a USDC spending policy: the whitelist allows transfer on any token