x402
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesex402 Skill
x402 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.
提供用于与x402付费API端点交互、发送收件箱消息、搭建新x402 API项目以及探索OpenRouter AI模型的工具。支付流程会通过已配置的钱包自动处理。
Usage
使用方法
bun run x402/x402.ts <subcommand> [options]bun run x402/x402.ts <子命令> [选项]Subcommands
子命令
list-endpoints
列出端点
List known x402 API endpoint sources with descriptions and usage examples.
bun run x402/x402.ts list-endpointsOutput:
json
{
"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": "..." }
}列出已知的x402 API端点源,包含描述和使用示例。
bun run x402/x402.ts list-endpoints输出:
json
{
"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
--pathnot 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):
json
{
"type": "free",
"endpoint": "GET https://x402.biwas.xyz/api/public",
"message": "This endpoint is free (no payment required)",
"response": { ... }
}Output (paid endpoint):
json
{
"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"
}
}探测x402 API端点以了解其使用成本,无需进行支付。
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"}]}'选项:
- (可选)—— HTTP方法(默认:GET)
--method - (可选)—— 完整端点URL,优先级高于
--url--path - (可选)—— API端点路径,未提供
--path时为必填项--url - (可选)—— API基础URL(默认:已配置的API_URL)
--api-url - (可选)—— 查询参数,为JSON对象
--params - (可选)—— POST/PUT请求的请求体,为JSON对象
--data
输出(免费端点):
json
{
"type": "free",
"endpoint": "GET https://x402.biwas.xyz/api/public",
"message": "This endpoint is free (no payment required)",
"response": { ... }
}输出(付费端点):
json
{
"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 to pay immediately.
--auto-approvebun 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-approveOptions:
- (optional) — HTTP method (default: GET)
--method - (optional) — Full endpoint URL. Takes precedence over
--url.--path - (optional) — API endpoint path. Required if
--pathnot 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:
json
{
"endpoint": "GET https://x402.biwas.xyz/api/pools/trending",
"response": { ... }
}执行x402 API端点。默认会先探测并显示付费端点的成本,使用参数可立即支付并执行。
--auto-approvebun 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选项:
- (可选)—— HTTP方法(默认:GET)
--method - (可选)—— 完整端点URL,优先级高于
--url--path - (可选)—— API端点路径,未提供
--path时为必填项--url - (可选)—— API基础URL(默认:已配置的API_URL)
--api-url - (可选)—— 查询参数,为JSON对象
--params - (可选)—— POST/PUT请求的请求体,为JSON对象
--data - (标志位)—— 跳过成本探测,立即执行并在需要时完成支付
--auto-approve
输出:
json
{
"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:
json
{
"success": true,
"message": "Message delivered",
"recipient": { "btcAddress": "bc1q...", "stxAddress": "SP..." },
"contentLength": 22,
"inbox": { ... },
"payment": { "txid": "0x...", "amount": "1000 sats sBTC" }
}向aibtc.com上另一个agent的收件箱发送付费x402消息。使用赞助式交易(无需STX gas费),需要一个已解锁且拥有sBTC余额的钱包。
bun run x402/x402.ts send-inbox-message \
--recipient-btc-address bc1q... \
--recipient-stx-address SP... \
--content "Hello from the agent!"选项:
- (必填)—— 收件人的比特币地址(bc1...格式)
--recipient-btc-address - (必填)—— 收件人的Stacks地址(SP...格式)
--recipient-stx-address - (必填)—— 消息内容(最多500字符)
--content
输出:
json
{
"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 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 description
description - — 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_write
tier
创建一个完整的x402付费API项目作为Cloudflare Worker。会生成一个包含Hono.js应用、x402支付中间件、wrangler配置和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"}]'选项:
- (必填)—— 项目文件夹将创建的目录
--output-dir - (必填)—— 项目名称(小写,用连字符分隔)
--project-name - (必填)—— 端点配置的JSON数组
--endpoints - (可选)—— 接收支付的Stacks地址(若省略则使用活跃钱包)
--recipient-address - (可选)—— 支付使用的网络(默认:主网)
--network - (可选)—— 自定义中继URL(默认:https://x402-relay.aibtc.com)
--relay-url
端点配置字段:
- —— 端点路径(例如:
path)/api/data - —— HTTP方法(GET或POST)
method - —— 端点描述
description - —— 支付金额(例如:
amount)"0.001" - —— 支付代币(STX、sBTC或USDCx)
tokenType - (可选)—— 定价层级:simple、standard、ai、heavy_ai、storage_read、storage_write
tier
scaffold-ai-endpoint
搭建AI端点项目
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, custom
aiType - (optional) — OpenRouter model override
model - (optional) — Custom system prompt
systemPrompt
创建一个集成OpenRouter的完整x402付费AI API项目作为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"}]'选项:
- (必填)—— 项目文件夹将创建的目录
--output-dir - (必填)—— 项目名称(小写,用连字符分隔)
--project-name - (必填)—— AI端点配置的JSON数组
--endpoints - (可选)—— 接收支付的Stacks地址(若省略则使用活跃钱包)
--recipient-address - (可选)—— 支付使用的网络(默认:主网)
--network - (可选)—— 自定义中继URL
--relay-url - (可选)—— 默认OpenRouter模型(默认:anthropic/claude-3-haiku)
--default-model
AI端点配置字段:
- 、
path、description、amount—— 与常规端点相同tokenType - —— AI操作类型:chat、completion、summarize、translate、custom
aiType - (可选)—— OpenRouter模型覆盖值
model - (可选)—— 自定义系统提示词
systemPrompt
openrouter-guide
OpenRouter指南
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
获取用于实现AI功能的OpenRouter集成示例和代码模式。
bun run x402/x402.ts openrouter-guide [--environment all] [--feature all]选项:
- (可选)—— 目标环境(nodejs、cloudflare-worker、browser、all)
--environment - (可选)—— 特定功能(chat、completion、streaming、function-calling、all)
--feature
openrouter-models
OpenRouter模型列表
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:
json
{
"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."
}列出热门的OpenRouter模型,包含其能力和上下文长度。
bun run x402/x402.ts openrouter-models [--category all]选项:
- (可选)—— 按类别筛选:fast、quality、cheap、code、long-context、all(默认:all)
--category
输出:
json
{
"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
注意事项
- and
execute-endpointrequire 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 gas
send-inbox-message - Scaffold commands generate a complete project — run in the generated directory to start
npm install && npm run dev - Network is controlled by the environment variable (default: testnet); use
NETWORKfor mainnet endpointsNETWORK=mainnet
- 和
execute-endpoint在端点需要付费时,需使用已解锁的钱包probe-endpoint - 需要已解锁且拥有sBTC余额的钱包;赞助式交易流程无需STX支付gas费
send-inbox-message - 脚手架命令会生成完整项目,在生成的目录中运行即可启动
npm install && npm run dev - 网络由环境变量控制(默认:testnet);使用
NETWORK可连接主网端点NETWORK=mainnet