402 Payment Required negotiation, constructs EIP-712 typed data, signs via a wallet provider, and retries the request with a payment signature.
Quickstart with Agent
The fastest way to get started — let your AI agent handle setup and payments for you.1
Install allium-cli
2
Install agent skills
3
Open your agent
Start Claude Code, Codex, or any compatible AI agent.
4
Ask a question
How It Works
1
Send request
Make a normal API request to any payment-enabled endpoint.
2
Receive 402
The server responds with
402 Payment Required and an accepts array of payment options.3
Sign payment
Your client constructs and signs an EIP-712 payment authorization via Privy server wallets — no private keys or gas needed.
4
Retry with signature
Resend the original request with the payment signature header attached.
5
6
Get data
Payment confirmed — you receive your data with a
200 response.Supported Tokens & Networks
x402 payments use USDC on the following networks:Implementation
This guide uses Privy server wallets for signing. Privy handles wallet creation and EIP-712 signing via its API — you never touch private keys or pay gas.Prerequisites
- Python 3.8+
- Privy account — free, takes 30 seconds
- USDC on Base or Solana (mainnet)
1. Set Up Privy
1
Create a Privy app
Go to dashboard.privy.io, sign up, and click Create App.
2
Copy your credentials
Copy your App ID and App Secret from the dialog and store them securely.
3
If you closed the dialog too soon
Go to Configuration → App settings → Basics → New Secret to generate a new App ID and App Secret pair.
4
Set environment variables
2. Install Dependencies
3. Create a Wallet
Create a server-managed wallet on Privy. This wallet will sign x402 payments on your behalf.4. Make a Paid API Call
Here’s a complete working example that fetches the current price of ETH. Thex402_request helper handles the full payment flow:
- Send the API request
- Receive a 402 response containing an
acceptsarray of payment options - Select a payment option matching your network (Base or Base Sepolia)
- Construct EIP-712 typed data for a USDC
TransferWithAuthorization(EIP-3009) - Sign via Privy using
eth_signTypedData_v4 - Build the x402 v2
PaymentPayloadand retry with thePAYMENT-SIGNATUREheader
EIP-712 Domain Configuration
The USDC contracts use different EIP-712 domains per network. These values are required when constructing theTransferWithAuthorization typed data for signing. They are provided in the 402 response’s accepts[].extra field.
Frontend Integration
Building a web app with embedded wallets? Use Privy’suseX402Fetch hook for seamless client-side x402 payments in React.