x402 payment protocol for AI agents. Enables autonomous micropayments using HTTP 402 status codes and stablecoins. Use when you need to pay for API access, a...
Autonomous payment protocol for AI agents using HTTP 402 + stablecoins.
x402 is an open standard for internet-native payments. It enables AI agents to pay for API calls automatically using stablecoins, without accounts or human intervention.
How it works:
Key benefits:
neckr0ik-x402-payments check https://api.example.com/premium
neckr0ik-x402-payments pay https://api.example.com/premium --amount 0.01
neckr0ik-x402-payments serve --port 8080 --price 0.01
Agent x402 Facilitator API Server
| | |
|-- GET /premium ------>|----------------------->|
| | |
|<-- HTTP 402 -----------|------------------------|
| (payment required) | |
| {amount, address, | |
| chain, facilitator}| |
| | |
|-- Sign payment ------>| |
| | |
| |-- Submit to chain --->|
| | |
| |<-- Confirmation ------|
| | |
|-- GET /premium --------|----------------------->|
| PAYMENT-SIGNATURE | |
| | |
|<-- 200 OK -------------|------------------------|
| (data) | |
Check if an endpoint supports x402 payments.
neckr0ik-x402-payments check <url>
Options:
--timeout <ms> Request timeout (default: 10000)
Pay for API access and receive data.
neckr0ik-x402-payments pay <url> [options]
Options:
--amount <amount> Maximum amount to pay (in USD)
--chain <chain> Preferred chain (default: base)
--token <token> Stablecoin token (default: usdc)
--wallet <address> Wallet to use for payment
--dry-run Show payment details without paying
Start an x402-enabled API server.
neckr0ik-x402-payments serve [options]
Options:
--port <port> Server port (default: 8080)
--price <amount> Price per request (in USD)
--chain <chain> Accept payments on chain (default: base)
--token <token> Accept stablecoin (default: usdc)
--wallet <address> Receiving wallet address
Check your payment wallet balance.
neckr0ik-x402-payments balance [options]
Options:
--chain <chain> Chain to check (default: all)
View payment history.
neckr0ik-x402-payments history [options]
Options:
--limit <n> Number of transactions (default: 10)
--chain <chain> Filter by chain
Set up your wallet for payments:
# Set wallet private key (stored securely)
neckr0ik-x402-payments config set wallet.private_key <key>
# Or use environment variable
export X402_PRIVATE_KEY=<key>
# Set receiving address for payments
neckr0ik-x402-payments config set wallet.address <address>
# Before: Need API key, account, subscription
response = requests.get("https://api.example.com/data",
headers={"Authorization": "Bearer YOUR_API_KEY"})
# After: Autonomous payment, no account needed
response = x402.get("https://api.example.com/data")
from x402 import PaymentMiddleware
app = Flask(__name__)
app.wsgi_app = PaymentMiddleware(app.wsgi_app, price=0.01)
@app.route("/premium-data")
def premium_data():
return {"data": "only accessible after payment"}
# Requests to /premium-data automatically require payment
references/x402-spec.md — Full protocol specificationreferences/facilitators.md — List of known facilitatorsscripts/x402.py — Payment implementationZIP package — ready to use