Turn any Python function into a zero-gas AI Agent API with x402 + USDC (Base + SKALE on Base)
x402-fast-monetization-template is an early-stage Python project in the AI payments / x402 ecosystem, focused on api-marketplace, fastapi, monetization, python. It currently has 0 GitHub stars and 1 forks, and sits alongside related tools like x402-sdk, x402-backend, agent-commerce-framework, agent-starter-python, ai-agent-directory, x402-openai-python.
Turn any Python function into a zero-gas AI Agent API — monetized with USDC, live in 3 steps.
This template lets you monetize any Python function as a pay-per-call API using USDC and the x402 protocol. One decorator is all it takes. No subscription logic, no API keys to manage for your callers, no billing infrastructure.
The killer feature: SKALE on Base is the default chain. SKALE on Base has ultra-low gas fees (~$0.0007/tx via CREDITS) — AI agents and bots can make hundreds of micro-payments per minute without burning money on gas. On Base you pay ~$0.001 per transaction; on SKALE on Base you pay a fraction of a cent.
git clone https://github.com/Wintyx57/x402-fast-monetization-template.git
cd x402-fast-monetization-template
pip install -r requirements.txt
cp .env.example .env
Open .env and set your wallet address:
Need USDC? Bridge from any chain → SKALE in 1 click: x402bazaar.org/fund
WALLET_ADDRESS=0xYOUR_ACTUAL_WALLET_ADDRESS
python main.py
Your API is live at http://localhost:8000/docs — open it to see the interactive Swagger UI.
The x402 protocol reuses the HTTP 402 status code ("Payment Required") to create a machine-readable payment flow that AI agents can navigate autonomously:
Client / AI Agent Your API Chain (SKALE or Base)
| | |
| 1. GET /generate_qr | |
|----------------------------->| |
| | |
| 2. 402 + payment_details | |
| (amount, wallet, network) | |
|<-----------------------------| |
| | |
| 3. Send USDC on SKALE | |
|---------------------------------------------------------------->|
| | |
| 4. GET /generate_qr | |
| + X-Payment-TxHash: 0x... | |
| + X-Payment-Chain: skale | |
|----------------------------->| |
| | 5. Verify tx on-chain |
| |--------------------------------->|
| | |
| 6. 200 + result | |
|<-----------------------------| |
X-Payment-TxHash and optionally X-Payment-Chain headers| Chain | Gas Cost | USDC Contract | Chain ID |
|---|---|---|---|
| Base | ~$0.001 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
8453 |
| SKALE on Base (default) | ~$0.0007 (CREDITS gas token) | 0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20 |
1187947933 |
| Polygon | ~$0.001 (MATIC) | 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359 |
137 |
All chains are listed in the 402 response under payment_details.networks so agents can pick the cheapest option automatically.
To change the default chain, set DEFAULT_CHAIN=base or DEFAULT_CHAIN=polygon in your .env.
One decorator turns any Python function into a paid FastAPI endpoint:
@x402_paywall(price=0.05, description="My paid API", tags=["cool"])
def my_function(param: str) -> dict:
return {"result": f"You sent: {param}"}
What happens automatically:
/my_function)?param=hello)dict -- JSON responsebytes -- Binary response (e.g., PNG image)str -- Plain text response402 with full payment instructionsX-Payment-TxHash get the function resultThe 402 response body that agents receive:
{
"error": "Payment Required",
"payment_details": {
"amount": "0.05",
"currency": "USDC",
"network": "SKALE on Base",
"chain_id": 1187947933,
"recipient": "0xYOUR_WALLET_ADDRESS",
"usdc_contract": "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
"networks": [
{ "chain": "base", "label": "Base", "chain_id": 8453, "gas": "~$0.001", ... },
{ "chain": "skale", "label": "SKALE on Base", "chain_id": 1187947933, "gas": "~$0.0007 (CREDITS)", ... }
],
"instructions": "Send USDC on SKALE on Base to the recipient address, then retry with headers X-Payment-TxHash: 0x... and X-Payer-Address: 0x... Optionally add X-Payment-Chain: base|skale to select the network."
}
}
Open main.py and go to Section 5. Adding a new paid endpoint is 3 lines:
@x402_paywall(price=0.02, description="Search my database", tags=["search", "data"])
def my_api(query: str, limit: int = 10) -> dict:
results = do_something(query, limit)
return {"data": results}
Restart the server — your endpoint is live at GET /my_api?query=hello&limit=5 and visible in /docs.
Decorator parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
price |
float |
Yes | Price in USDC per call |
description |
str |
No | Shown in Swagger UI and marketplace |
tags |
list[str] |
No | Used for categorization |
The template ships with 3 working endpoints, no external API keys required:
| Endpoint | Price (USDC) | Description | Returns |
|---|---|---|---|
/generate_qr |
0.05 | Generate a QR code image from text | PNG image |
/summarize |
0.03 | Summarize text (extractive, word-freq) | JSON |
/random_joke |
0.01 | Get a random programming joke | JSON |
| Variable | Required | Default | Description |
|---|---|---|---|
WALLET_ADDRESS |
Yes | -- | Your Ethereum address to receive USDC payments |
DEFAULT_CHAIN |
No | skale |
Default payment chain: skale or base |
BASE_RPC_URL |
No | chain default | Override the Base RPC endpoint |
BAZAAR_REGISTRY_URL |
No | -- | x402 Bazaar URL for auto-registering your endpoints |
API_BASE_URL |
No | http://localhost:8000 |
Public URL of your API (used for marketplace) |
PORT |
No | 8000 |
Server listening port |
Replit (one-click):
WALLET_ADDRESS in the Replit Secrets tabRailway / Render:
# Set environment variables in the dashboard, then deploy:
git push
Both platforms detect Python automatically. Set WALLET_ADDRESS and optionally DEFAULT_CHAIN in the environment variables panel.
| Resource | URL |
|---|---|
| x402 Bazaar marketplace | x402bazaar.org |
| Backend API | x402-api.onrender.com |
CLI (npx x402-bazaar) |
x402-bazaar-cli |
| TypeScript SDK | x402-sdk |
| LangChain tools | x402-langchain |
| MCP Server | x402-backend |
MIT — Use it, fork it, monetize with it.
x402 Payment Protocol SDKs - Dead simple micropayments for APIs and AI agents
API marketplace powered by HTTP 402 protocol — AI agents pay per call with USDC on Base. 69 native endpoints, on-chain payment verification, multi-chain (Base + SKALE).
Open-source marketplace where AI agents autonomously discover, negotiate, and purchase API services. x402 USDC payments, MCP bridge, reputation engine. MIT license.
Minimal nullpath agent starter (Python + FastAPI). Register, execute, get paid via x402.
Pay-per-use B2A discovery API for AI agents — built on x402 (USDC micropayments on Base)
Drop-in OpenAI Python client with transparent x402 payment support.
The agent-native LLM router for autonomous agents. 55+ models (8 free), <1ms local routing, USDC payments on Base & Solana via x402.
The AI agent with a wallet — spends USDC autonomously to get real work done. Apache-2.0, TypeScript.
The first agentic payment network: policy-controlled, gasless, and real money-ready. OmniClaw CLI + Financial Policy Engine let autonomous agents pay and earn safely at machine speed.
An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.
x402 Ecosystem Explorer
🚀 Curated list of x402 resources: HTTP 402 Payment Required protocol for blockchain payments, crypto micropayments, AI agents, API monetization. Includes SDKs (TypeScript, Python, Rust), examples, facilitators (Coinbase, Cloudflare), MCP integration, tutorials. Accept USDC payments with one line of code. Perfect for AI agent economy.