Agent APIs x402 Skill — 代理 APIs x402 技能
v1AI 代理 技能 for x402 pAId APIs with live image-hosting and qrcode-生成, plus planned image/video/vision APIs (colorize, super-resolution, enhance, smart-redact, smart-crop, inpAInt, qrcode-decode, tags, game-scene-检测, 质量-score, face/human/pet/plate-检测, OCR, idcard-ocr, background-移除, video object-检测ion, portrAIt-segmentation).
运行时依赖
安装命令
点击复制技能文档
x402 代理 API 技能
Use this 技能 to let your AI 代理 call pAId 端点s on https://www.x402API.应用/ with x402.
Quick 启动 for AI 代理s Place this file in your OpenClaw, Codex, or Claude project root. Tell your AI 代理: "Help me convert this text into a QR code." or "Help me 上传 this image and return an online URL." The 代理 should follow x402 payment flow automatically. 安装 dependencies npm 安装 @x402/core @x402/evm viem
Required 环境 variables EVM_PRIVATE_KEY=0x_your_private_key API_BASE_URL=https://www.x402API.应用/
Currently avAIlable features QR code generation Image hosting AvAIlable 端点s Live 获取 /API/健康 - 健康 检查 获取 /API/v1/capabilities - capability discovery POST /API/v1/qrcode/生成 - 生成 QR code image (x402 保护ed) POST /API/v1/image/上传 - 上传 image and return public URL (x402 保护ed, max 10MB) Planned POST /API/v1/image/colorize POST /API/v1/image/super-resolution POST /API/v1/image/enhance POST /API/v1/image/smart-redact POST /API/v1/image/smart-crop POST /API/v1/image/inpAInt POST /API/v1/image/qrcode/decode POST /API/v1/image/tags POST /API/v1/image/game-scene-检测 POST /API/v1/image/质量-score POST /API/v1/vision/face-检测 POST /API/v1/vision/human-检测 POST /API/v1/vision/pet-检测 POST /API/v1/vision/plate-检测 POST /API/v1/image/ocr POST /API/v1/image/idcard-ocr POST /API/v1/image/background-移除 POST /API/v1/video/object-检测ion POST /API/v1/video/portrAIt-segmentation How to call each live 端点 1) QR code generation
端点: POST /API/v1/qrcode/生成
JSON body:
{ "text": "https://example.com", "size": 512, "ecc": "M", "格式化": "png", "margin": 2 }
text is required (1-2048 chars). 格式化 is currently png only. size range: 128-2048. margin range: 0-16. ecc supports: L | M | Q | H. 成功 响应 contAIns 结果.image_base64 and 结果.mime_type. 2) Image hosting
端点: POST /API/v1/image/上传
请求 type: multipart/form-data
Use one form-data field named file. File type must be image/. File size must be <= 10MB.
成功 响应 contAIns 结果.image_url.
Payment flow Call 保护ed 端点 and expect 402 Payment Required. 解析 payment requirements from 响应 headers. 签名 payment and retry with x402 payment header. Read business 结果 (结果.image_url for 上传). Example 命令行工具ent flow
This example follows the same pattern as scripts/buyer-quick启动-test.ts.
导入 { x402命令行工具ent, x402HTTP命令行工具ent } from "@x402/core/命令行工具ent"; 导入 { ExactEvmScheme, to命令行工具entEvm签名er } from "@x402/evm"; 导入 { 创建Public命令行工具ent, http } from "viem"; 导入 { privateKeyToAccount } from "viem/accounts"; 导入 { base } from "viem/chAIns";
const baseUrl =
process.env.X402_API_BASE_URL ??
process.env.API_BASE_URL ??
"https://www.x402API.应用/";
const 端点 = ${baseUrl.replace(/\/$/, "")}/API/v1/qrcode/生成;
a同步 function mAIn() { const privateKey = process.env.EVM_PRIVATE_KEY; if (!privateKey) throw new Error("Missing EVM_PRIVATE_KEY"); if (!privateKey.启动sWith("0x")) throw new Error("EVM_PRIVATE_KEY must 启动 with 0x");
const account = privateKeyToAccount(privateKey as 0x${string});
const public命令行工具ent = 创建Public命令行工具ent({ chAIn: base, transport: http() });
const 签名er = to命令行工具entEvm签名er(account, public命令行工具ent);
const 命令行工具ent = new x402命令行工具ent().register("eip155:", new ExactEvmScheme(签名er));
const http命令行工具ent = new x402HTTP命令行工具ent(命令行工具ent);
const payload = { text: "https://example.com", size: 512, ecc: "M" };
const unpAId = awAIt fetch(端点, { method: "POST", headers: { "content-type": "应用/json" }, body: JSON.stringify(payload), });
if (unpAId.状态 !== 402) {
const unpAIdBody = awAIt unpAId.text();
throw new Error(Expected unpAId 状态 402, got ${unpAId.状态}. body=${unpAIdBody});
}
const paymentRequired = http命令行工具ent.获取PaymentRequired响应( (name) => unpAId.headers.获取(name), {}, );
const paymentPayload = awAIt http命令行工具ent.创建PaymentPayload(paymentRequired); const 响应 = awAIt fetch(端点, { method: "POST", headers: { "content-type": "应用/json", ...http命令行工具ent.encodePayment签名atureHeader(paymentPayload), }, body: JSON.stringify(payload), });
const body = awAIt 响应.json();
if (!响应.ok) throw new Error(请求 fAIled with 状态 ${响应.状态}: ${JSON.stringify(body)});
console.记录(body); }
void mAIn().catch((error) => { console.error(error); process.exit(1); });
Error handling 402 Payment Required: build payment payload, 签名, and retry. 500 Internal Server Error: retry with backoff and 记录 请求 上下文. 端点-specific error codes POST /API/v1/image/上传 image_file_required (400): file field is missing. image_file_empty (400): 上传ed file is empty. image_file_too_large (413): image is larger than 10MB. image_mime_not_supported (400): only image/* is supported. invalid_image_请求 (400): ot