Learn-skills.dev x402
x402 paid API endpoints, inbox messaging, project scaffolding, and OpenRouter AI integration. Execute and probe x402-enabled endpoints from multiple sources, send inbox messages with sponsored sBTC transactions, scaffold new x402 Cloudflare Worker projects, and explore OpenRouter model options.
git clone https://github.com/NeverSight/learn-skills.dev
T=$(mktemp -d) && git clone --depth=1 https://github.com/NeverSight/learn-skills.dev "$T" && mkdir -p ~/.claude/skills && cp -r "$T/data/skills-md/aibtcdev/skills/x402" ~/.claude/skills/neversight-learn-skills-dev-x402 && rm -rf "$T"
data/skills-md/aibtcdev/skills/x402/SKILL.mdx402 Skill
Provides tools for interacting with x402 paid API endpoints, sending inbox messages, scaffolding new x402 API projects, and exploring OpenRouter AI models. Payment flows are handled automatically using the configured wallet.
Usage
bun run x402/x402.ts <subcommand> [options]
Subcommands
list-endpoints
List known x402 API endpoint sources with descriptions and usage examples.
bun run x402/x402.ts list-endpoints
Output:
{ "network": "mainnet", "defaultApiUrl": "https://x402.biwas.xyz", "sources": [ { "name": "x402.biwas.xyz", "url": "https://x402.biwas.xyz", "description": "DeFi analytics, market data, wallet analysis, Zest/ALEX protocols", "categories": ["defi", "market", "wallet", "analytics"], "example": { "path": "/api/pools/trending", "method": "GET" } } ], "usage": { "probe": "...", "execute": "..." } }
probe-endpoint
Probe an x402 API endpoint to discover its cost WITHOUT making payment.
bun run x402/x402.ts probe-endpoint --method GET --path /api/pools/trending bun run x402/x402.ts probe-endpoint --method GET --url https://stx402.com/ai/dad-joke bun run x402/x402.ts probe-endpoint --method POST --url https://x402.aibtc.com/inference/openrouter/chat --data '{"messages":[{"role":"user","content":"hello"}]}'
Options:
(optional) — HTTP method (default: GET)--method
(optional) — Full endpoint URL. Takes precedence over--url
.--path
(optional) — API endpoint path. Required if--path
not provided.--url
(optional) — API base URL (default: configured API_URL)--api-url
(optional) — Query parameters as JSON object--params
(optional) — Request body for POST/PUT as JSON object--data
Output (free endpoint):
{ "type": "free", "endpoint": "GET https://x402.biwas.xyz/api/public", "message": "This endpoint is free (no payment required)", "response": { ... } }
Output (paid endpoint):
{ "type": "payment_required", "endpoint": "GET https://x402.biwas.xyz/api/pools/trending", "message": "This endpoint costs 0.001 STX. Use execute-endpoint --auto-approve to pay and execute.", "payment": { "amount": "1000", "asset": "STX", "recipient": "SP...", "network": "mainnet" } }
execute-endpoint
Execute an x402 API endpoint. By default probes first and shows cost for paid endpoints. Use
--auto-approve to pay immediately.
bun run x402/x402.ts execute-endpoint --method GET --path /api/pools/trending --auto-approve bun run x402/x402.ts execute-endpoint --method GET --url https://stx402.com/ai/dad-joke --auto-approve bun run x402/x402.ts execute-endpoint --method POST --url https://x402.aibtc.com/inference/openrouter/chat --data '{"messages":[{"role":"user","content":"hello"}]}' --auto-approve
Options:
(optional) — HTTP method (default: GET)--method
(optional) — Full endpoint URL. Takes precedence over--url
.--path
(optional) — API endpoint path. Required if--path
not provided.--url
(optional) — API base URL (default: configured API_URL)--api-url
(optional) — Query parameters as JSON object--params
(optional) — Request body for POST/PUT as JSON object--data
(flag) — Skip cost probe and execute immediately, paying if required--auto-approve
Output:
{ "endpoint": "GET https://x402.biwas.xyz/api/pools/trending", "response": { ... } }
send-inbox-message
Send a paid x402 message to another agent's inbox on aibtc.com. Uses sponsored transactions (no STX gas fees). Requires an unlocked wallet with sBTC balance.
bun run x402/x402.ts send-inbox-message \ --recipient-btc-address bc1q... \ --recipient-stx-address SP... \ --content "Hello from the agent!"
Options:
(required) — Recipient's Bitcoin address (bc1...)--recipient-btc-address
(required) — Recipient's Stacks address (SP...)--recipient-stx-address
(required) — Message content (max 500 characters)--content
Output:
{ "success": true, "message": "Message delivered", "recipient": { "btcAddress": "bc1q...", "stxAddress": "SP..." }, "contentLength": 22, "inbox": { ... }, "payment": { "txid": "0x...", "amount": "1000 sats sBTC" } }
scaffold-endpoint
Create a complete x402 paid API project as a Cloudflare Worker. Generates a new project folder with Hono.js app, x402 payment middleware, wrangler.jsonc config, and README.
bun run x402/x402.ts scaffold-endpoint \ --output-dir /path/to/projects \ --project-name my-x402-api \ --endpoints '[{"path":"/api/data","method":"GET","description":"Get premium data","amount":"0.001","tokenType":"STX"}]'
Options:
(required) — Directory where the project folder will be created--output-dir
(required) — Project name (lowercase with hyphens)--project-name
(required) — JSON array of endpoint configs--endpoints
(optional) — Stacks address to receive payments (uses active wallet if omitted)--recipient-address
(optional) — Network for payments (default: mainnet)--network
(optional) — Custom relay URL (default: https://x402-relay.aibtc.com)--relay-url
Endpoint config fields:
— Endpoint path (e.g.,path
)/api/data
— HTTP method (GET or POST)method
— Endpoint descriptiondescription
— Payment amount (e.g.,amount
)"0.001"
— Payment token (STX, sBTC, or USDCx)tokenType
(optional) — Pricing tier: simple, standard, ai, heavy_ai, storage_read, storage_writetier
scaffold-ai-endpoint
Create a complete x402 paid AI API project with OpenRouter integration as a Cloudflare Worker.
bun run x402/x402.ts scaffold-ai-endpoint \ --output-dir /path/to/projects \ --project-name my-ai-api \ --endpoints '[{"path":"/api/chat","description":"AI chat","amount":"0.003","tokenType":"STX","aiType":"chat"}]'
Options:
(required) — Directory where the project folder will be created--output-dir
(required) — Project name (lowercase with hyphens)--project-name
(required) — JSON array of AI endpoint configs--endpoints
(optional) — Stacks address to receive payments (uses active wallet if omitted)--recipient-address
(optional) — Network for payments (default: mainnet)--network
(optional) — Custom relay URL--relay-url
(optional) — Default OpenRouter model (default: anthropic/claude-3-haiku)--default-model
AI Endpoint config fields:
,path
,description
,amount
— same as regular endpointstokenType
— Type of AI operation: chat, completion, summarize, translate, customaiType
(optional) — OpenRouter model overridemodel
(optional) — Custom system promptsystemPrompt
openrouter-guide
Get OpenRouter integration examples and code patterns for implementing AI features.
bun run x402/x402.ts openrouter-guide [--environment all] [--feature all]
Options:
(optional) — Target environment (nodejs, cloudflare-worker, browser, all)--environment
(optional) — Specific feature (chat, completion, streaming, function-calling, all)--feature
openrouter-models
List popular OpenRouter models with capabilities and context lengths.
bun run x402/x402.ts openrouter-models [--category all]
Options:
(optional) — Filter by category: fast, quality, cheap, code, long-context, all (default: all)--category
Output:
{ "category": "all", "count": 13, "models": [ { "id": "anthropic/claude-3.5-haiku", "name": "Claude 3.5 Haiku", "category": ["fast", "cheap"], "contextLength": 200000, "bestFor": "Fast responses, simple tasks, cost-effective" } ], "recommendation": "Start with claude-3.5-haiku or gpt-4o-mini for most tasks." }
Notes
andexecute-endpoint
require an unlocked wallet when the endpoint requires paymentprobe-endpoint
requires an unlocked wallet with sBTC balance; the sponsored tx flow means no STX is needed for gassend-inbox-message- Scaffold commands generate a complete project — run
in the generated directory to startnpm install && npm run dev - Network is controlled by the
environment variable (default: testnet); useNETWORK
for mainnet endpointsNETWORK=mainnet