Drop-in x402 payment middleware for Flask APIs. Add machine-to-machine payments to any OpenClaw platform in 5 lines.
Part of the Beacon Protocol ecosystem — provides the payment layer for beacon_skill.x402_bridge and the Compute Marketplace.
pip install openclaw-x402from flask import Flask, jsonify
from openclaw_x402 import X402Middleware
app = Flask(__name__)
x402 = X402Middleware(app, treasury="0xYourBaseAddress")
@app.route("/api/premium/data")
@x402.premium(price="10000", description="Premium data export") # $0.01 USDC
def premium_data():
return jsonify({"data": "your premium content"})
# Free endpoints work normally — no decorator needed
@app.route("/api/public/data")
def public_data():
return jsonify({"data": "free content"})- Agent hits your premium endpoint
- Gets back HTTP 402 with payment instructions (USDC amount, treasury address, facilitator URL)
- Agent pays via Coinbase wallet on Base chain
- Agent retries with
X-PAYMENTheader containing tx hash - Middleware verifies payment via Coinbase facilitator
- Access granted
Set price="0" to pass all requests through without payment — useful for testing the flow before charging.
@x402.premium(price="0", description="Free for now")
def free_premium():
return jsonify({"data": "free during testing"})| Env Var | Purpose |
|---|---|
CDP_API_KEY_NAME |
Coinbase Developer Platform API key name |
CDP_API_KEY_PRIVATE_KEY |
CDP API private key |
Get credentials at portal.cdp.coinbase.com.
| Token | Address |
|---|---|
| USDC | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| wRTC | 0x5683C10596AaA09AD7F4eF13CAB94b9b74A669c6 |
| Aerodrome Pool | 0x4C2A0b915279f0C22EA766D58F9B815Ded2d2A3F |
- Beacon Protocol — Agent orchestrator (13 transports, scorecard dashboard)
- Elyan Compute Skill — GPU compute marketplace (uses this middleware)
- x402 Protocol — HTTP 402 Payment Required standard
- Coinbase Agentic Wallets
- RustChain — Proof-of-Antiquity blockchain
- BoTTube — AI video platform using openclaw-x402
- Aerodrome DEX — Swap USDC to wRTC
MIT