monetize-serviceBuild and deploy a paid API that other agents can pay to use via x402. Use when you or the user want to monetize an API, make money, earn money, offer a service, sell a service to other agents, charge for endpoints, create a paid endpoint, or set up a paid service. Covers "make money by offering an endpoint", "sell a service", "monetize your data", "create a paid API".
Install via ClawdBot CLI:
clawdbot install 0xRAG/monetize-serviceCreate an Express server that charges USDC for API access using the x402 payment protocol. Callers pay per-request in USDC on Base — no accounts, API keys, or subscriptions needed.
x402 is an HTTP-native payment protocol. When a client hits a protected endpoint without paying, the server returns HTTP 402 with payment requirements. The client signs a USDC payment and retries with a payment header. The facilitator verifies and settles the payment, and the server returns the response.
npx awal@latest status
If the wallet is not authenticated, refer to the authenticate-wallet skill.
Run this to get the wallet address that will receive payments:
npx awal@latest address
Use this address as the payTo value.
mkdir x402-server && cd x402-server
npm init -y
npm install express x402-express
Create index.js:
const express = require("express");
const { paymentMiddleware } = require("x402-express");
const app = express();
app.use(express.json());
const PAY_TO = "<address from step 1>";
// x402 payment middleware — protects routes below
const payment = paymentMiddleware(PAY_TO, {
"GET /api/example": {
price: "$0.01",
network: "base",
config: {
description: "Description of what this endpoint returns",
},
},
});
// Protected endpoint
app.get("/api/example", payment, (req, res) => {
res.json({ data: "This costs $0.01 per request" });
});
app.listen(3000, () => console.log("Server running on port 3000"));
node index.js
Test with curl — you should get a 402 response with payment requirements:
curl -i http://localhost:3000/api/example
Creates Express middleware that enforces x402 payments.
| Parameter | Type | Description |
| ------------- | -------- | ----------------------------------------------------- |
| payTo | string | Ethereum address (0x...) to receive USDC payments |
| routes | object | Route config mapping route patterns to payment config |
| facilitator | object? | Optional custom facilitator (defaults to x402.org) |
Each key in the routes object is "METHOD /path". The value is either a price string or a config object:
// Simple — just a price
{ "GET /api/data": "$0.05" }
// Full config
{
"POST /api/query": {
price: "$0.25",
network: "base",
config: {
description: "Human-readable description of the endpoint",
inputSchema: {
bodyType: "json",
bodyFields: {
query: { type: "string", description: "The query to run" },
},
},
outputSchema: {
type: "object",
properties: {
result: { type: "string" },
},
},
},
},
}
| Field | Type | Description |
| ------------------------- | ------- | -------------------------------------------------- |
| price | string | USDC price (e.g. "$0.01", "$1.00") |
| network | string | Blockchain network: "base" or "base-sepolia" |
| config.description | string? | What this endpoint does (shown to clients) |
| config.inputSchema | object? | Expected request body/query schema |
| config.outputSchema | object? | Response body schema |
| config.maxTimeoutSeconds | number? | Max time for payment settlement |
| Network | Description |
| -------------- | ------------------------------ |
| base | Base mainnet (real USDC) |
| base-sepolia | Base Sepolia testnet (test USDC) |
const payment = paymentMiddleware(PAY_TO, {
"GET /api/cheap": { price: "$0.001", network: "base" },
"GET /api/expensive": { price: "$1.00", network: "base" },
"POST /api/query": { price: "$0.25", network: "base" },
});
app.get("/api/cheap", payment, (req, res) => { /* ... */ });
app.get("/api/expensive", payment, (req, res) => { /* ... */ });
app.post("/api/query", payment, (req, res) => { /* ... */ });
const payment = paymentMiddleware(PAY_TO, {
"GET /api/*": { price: "$0.05", network: "base" },
});
app.use(payment);
app.get("/api/users", (req, res) => { /* ... */ });
app.get("/api/posts", (req, res) => { /* ... */ });
Register free endpoints before the payment middleware:
app.get("/health", (req, res) => res.json({ status: "ok" }));
// Payment middleware only applies to routes registered after it
app.get("/api/data", payment, (req, res) => { /* ... */ });
const payment = paymentMiddleware(PAY_TO, {
"POST /api/analyze": {
price: "$0.10",
network: "base",
config: {
description: "Analyze text sentiment",
inputSchema: {
bodyType: "json",
bodyFields: {
text: { type: "string", description: "Text to analyze" },
},
},
outputSchema: {
type: "object",
properties: {
sentiment: { type: "string" },
score: { type: "number" },
},
},
},
},
});
app.post("/api/analyze", payment, (req, res) => {
const { text } = req.body;
// ... your logic
res.json({ sentiment: "positive", score: 0.95 });
});
For production use with the Coinbase facilitator (supports mainnet):
npm install @coinbase/x402
const { facilitator } = require("@coinbase/x402");
const payment = paymentMiddleware(PAY_TO, routes, facilitator);
This requires CDP_API_KEY_ID and CDP_API_KEY_SECRET environment variables. Get these from https://portal.cdp.coinbase.com.
Once the server is running, use the pay-for-service skill to test payments:
# Check the endpoint's payment requirements
npx awal@latest x402 details http://localhost:3000/api/example
# Make a paid request
npx awal@latest x402 pay http://localhost:3000/api/example
| Use Case | Suggested Price |
| ---------------------- | --------------- |
| Simple data lookup | $0.001 - $0.01 |
| API proxy / enrichment | $0.01 - $0.10 |
| Compute-heavy query | $0.10 - $0.50 |
| AI inference | $0.05 - $1.00 |
npx awal@latest addressexpress and x402-expresscurl (should get 402) and npx awal@latest x402 pay (should get 200)Generated Mar 1, 2026
A startup offers a specialized AI model, such as for image generation or text summarization, as a paid API. Other agents or developers pay per request to access the model, enabling the startup to generate revenue without managing user accounts or subscriptions. This is ideal for niche AI services with high computational costs.
A financial data provider sets up a paid API to deliver real-time stock prices or cryptocurrency data. Clients pay per request to retrieve the latest market information, ensuring the provider earns money directly from usage. This model suits industries where timely data is valuable and can be monetized incrementally.
A company develops an API that analyzes user-generated content for inappropriate material, such as hate speech or spam. Other platforms integrate this service and pay per request to moderate their content, creating a revenue stream based on usage volume. This is useful for social media or gaming companies outsourcing moderation.
A logistics firm offers a paid API that provides optimized routing or address validation for delivery services. Clients in e-commerce or transportation pay per request to access these features, helping the firm monetize its proprietary algorithms. This scenario leverages data-driven insights in supply chain management.
Charge a fixed fee for each API call, such as $0.01 per request, allowing users to pay only for what they use without upfront commitments. This model is simple to implement with x402 and scales with usage, making it attractive for variable-demand services. It eliminates the need for subscription management or API keys.
Offer different API endpoints at varying price points, such as a basic endpoint for $0.001 and a premium one for $1.00, catering to diverse user needs and willingness to pay. This allows upselling based on functionality or data quality. Revenue is generated from a mix of low- and high-value transactions.
Provide free access to basic endpoints, like a health check, while charging for advanced features or higher usage limits through paid endpoints. This encourages user adoption and monetizes power users. Revenue comes from conversions to paid services as demand increases.
💬 Integration Tip
Start with a single endpoint to test payment flow, then expand to multiple routes using wildcard patterns for scalability.
Connect Claude to Clawdbot instantly and keep it connected 24/7. Run after setup to link your subscription, then auto-refreshes tokens forever.
ERC-8004 Trustless Agents - Register, discover, and build reputation for AI agents on Ethereum. Use when registering agents on-chain, querying agent registries, giving/receiving reputation feedback, or interacting with the AI agent trust layer.
Autonomous crypto trading on Base via Bankr. Use for trading tokens, monitoring launches, executing strategies, or managing a trading portfolio. Triggers on "trade", "buy", "sell", "launch", "snipe", "profit", "PnL", "portfolio balance", or any crypto trading task on Base.
Deploy ERC20 tokens on Base using Clanker SDK. Create tokens with built-in Uniswap V4 liquidity pools. Supports Base mainnet and Sepolia testnet. Requires PRIVATE_KEY in config.
Query DeFi portfolio data across 50+ chains via Zapper's GraphQL API. Use when the user wants to check wallet balances, DeFi positions, NFT holdings, token prices, or transaction history. Supports Base, Ethereum, Polygon, Arbitrum, Optimism, and more. Requires ZAPPER_API_KEY.
Interact with Solana blockchain via Helius APIs. Create/manage wallets, check balances (SOL + tokens), send transactions, swap tokens via Jupiter, and monitor addresses. Use for any Solana blockchain operation, crypto wallet management, token transfers, DeFi swaps, or portfolio tracking.