x402engine
Call 63 paid APIs via x402 micropayments. Each API call costs between $0.001 and $0.60, paid with USDC on Base/Solana or USDm on MegaETH.
What this skill does
This skill signs and submits stablecoin micropayments to call remote APIs on the user's behalf. It uses the EVMPRIVATEKEY environment variable to sign on-chain payment transactions. Each call deducts a small amount from the wallet.
Cost transparency: When presenting results, include the cost of the call (e.g. "Bitcoin is $97,500 (cost: $0.001)"). If the user asks about spending, show full budget breakdown.
Triggers
- - "what's the price of bitcoin"
- "ethereum price"
- "show me trending crypto"
- "generate an image of a sunset"
- "run this python code"
- "transcribe this audio"
- "wallet activity of vitalik.eth"
- "ask gpt to explain x402"
- "scrape this url"
- "pin this to ipfs"
- "resolve vitalik.eth"
- "flights from JFK to LAX"
- "search hotels in Paris"
- "find cheap flights to Tokyo"
- "how much budget is left"
- "list available services"
How it works
- 1. Fetch cached service catalog from discovery endpoint (default: https://x402engine.app/.well-known/x402.json).
- Score query against 63 service descriptions to find best match.
- Run policy preflight — check per-tx caps, daily caps, and recipient allowlist before signing.
- Call service via @x402/fetch — handles 402 payment flow automatically.
- Return structured data to the agent for natural-language presentation.
Rules
- - Present results naturally. Include the cost of each call so the user knows what was spent.
- If a payment fails due to insufficient funds, tell the user: "I need funds to access this service. Add USDC to your wallet to continue."
- If no matching service is found, say so plainly — don't expose internal routing details.
- Policy limits are authoritative — do not bypass spend caps or recipient allowlists.
- Keep all decisions explainable with reason codes internally.
Security
Required credential
- - EVMPRIVATEKEY (required) — signs payment transactions. Use a dedicated wallet with limited funds — never your primary wallet. If not set, an ephemeral key is generated (no real funds, no payments possible).
Optional configuration
These environment variables are NOT required. They provide additional controls:
- - EVMPRIVATEKEYFILE — alternative to EVMPRIVATEKEY; reads the key from a file instead of an env var. Use one or the other, not both.
- X402POLICYPATH — path to a JSON policy file. Defines per-transaction caps, daily spending limits, and a recipient allowlist. Without this, no spending limits are enforced beyond the wallet's on-chain balance. When configured, the engine is fail-closed: if the file is missing or invalid, all payments are denied.
- X402STATEPATH — path to a JSON file tracking daily spend and rate-limit state. Defaults to
.x402engine-state.json. - X402DISCOVERYURL — override the service catalog URL (default:
https://x402engine.app/.well-known/x402.json). Use a self-hosted catalog if you don't trust the default. - X402AUTOPREFLIGHT — set to
false to skip policy preflight checks. Enabled by default. - X402DISCOVERYREFRESH_MS — cache TTL for the service catalog in milliseconds.
How payments work
All payments go to the
payTo address declared in the service catalog. The catalog is fetched from the discovery URL above. If you want to restrict which addresses can receive payments, configure a policy file with a recipient allowlist.
Budget check
When the user asks "how much budget is left" or similar:
- - Load policy and state files.
- Show daily cap remaining per chain/asset if caps are enabled.
- Show rate limit status.
- Show wallet balance.
Dependencies
This skill requires Node.js and the following npm packages (declared in package.json):
- -
@x402/fetch — x402 payment-aware fetch wrapper - INLINECODE5 — EVM payment scheme (Permit2 signatures)
- INLINECODE6 — Ethereum client library
Install with: INLINECODE7
Reason Codes
- -
POLICY_MISSING, INLINECODE9 - INLINECODE10 ,
ASSET_DENIED, INLINECODE12 - INLINECODE13 ,
DAILY_CAP_EXCEEDED, INLINECODE15 - INLINECODE16
- INLINECODE17
- INLINECODE18
x402engine
通过x402微支付调用63个付费API。每次API调用费用在0.001美元到0.60美元之间,使用Base/Solana上的USDC或MegaETH上的USDm支付。
此技能的功能
此技能代表用户签署并提交稳定币微支付,以调用远程API。它使用EVMPRIVATEKEY环境变量签署链上支付交易。每次调用都会从钱包中扣除少量金额。
成本透明: 呈现结果时,包含调用的成本(例如比特币价格为97,500美元(成本:0.001美元))。如果用户询问支出情况,显示完整的预算明细。
触发条件
- - 比特币价格是多少
- 以太坊价格
- 显示热门加密货币
- 生成一张日落图片
- 运行这段Python代码
- 转录音频
- vitalik.eth的钱包活动
- 让GPT解释x402
- 抓取此URL
- 固定到IPFS
- 解析vitalik.eth
- 从JFK到LAX的航班
- 搜索巴黎的酒店
- 查找前往东京的廉价航班
- 还剩多少预算
- 列出可用服务
工作原理
- 1. 从发现端点获取缓存的服务目录(默认:https://x402engine.app/.well-known/x402.json)。
- 对63个服务描述进行评分查询,找到最佳匹配。
- 运行策略预检——在签署前检查每笔交易限额、每日限额和接收者白名单。
- 通过@x402/fetch调用服务——自动处理402支付流程。
- 向代理返回结构化数据,用于自然语言呈现。
规则
- - 自然地呈现结果。包含每次调用的成本,让用户知道花费了多少。
- 如果因资金不足导致支付失败,告知用户:我需要资金才能访问此服务。请向您的钱包添加USDC以继续。
- 如果未找到匹配的服务,直接说明——不要暴露内部路由细节。
- 策略限制具有权威性——不要绕过支出限额或接收者白名单。
- 所有决策内部都应附带可解释的原因代码。
安全性
必需凭证
- - EVMPRIVATEKEY(必需)——签署支付交易。使用资金有限的专用钱包——切勿使用您的主钱包。如果未设置,将生成临时密钥(无真实资金,无法进行支付)。
可选配置
以下环境变量不是必需的。它们提供额外的控制:
- - EVMPRIVATEKEYFILE——EVMPRIVATEKEY的替代方案;从文件而非环境变量读取密钥。使用其中一个,不要同时使用。
- X402POLICYPATH——JSON策略文件的路径。定义每笔交易限额、每日支出限额和接收者白名单。如果没有此配置,除钱包的链上余额外,不强制执行任何支出限制。配置后,引擎为故障关闭模式:如果文件缺失或无效,所有支付将被拒绝。
- X402STATEPATH——跟踪每日支出和速率限制状态的JSON文件路径。默认为.x402engine-state.json。
- X402DISCOVERYURL——覆盖服务目录URL(默认:https://x402engine.app/.well-known/x402.json)。如果您不信任默认目录,请使用自托管目录。
- X402AUTOPREFLIGHT——设置为false以跳过策略预检检查。默认启用。
- X402DISCOVERYREFRESH_MS——服务目录的缓存TTL,以毫秒为单位。
支付工作原理
所有支付都发送到服务目录中声明的payTo地址。目录从上述发现URL获取。如果您想限制哪些地址可以接收支付,请配置包含接收者白名单的策略文件。
预算检查
当用户询问还剩多少预算或类似问题时:
- - 加载策略和状态文件。
- 如果启用了限额,显示每个链/资产的每日剩余限额。
- 显示速率限制状态。
- 显示钱包余额。
依赖项
此技能需要Node.js和以下npm包(在package.json中声明):
- - @x402/fetch——支持x402支付的fetch包装器
- @x402/evm——EVM支付方案(Permit2签名)
- viem——以太坊客户端库
安装方式:cd skills/x402engine && npm install
原因代码
- - POLICYMISSING、POLICYINVALID
- CHAINDENIED、ASSETDENIED、RECIPIENTDENIED
- PERTXEXCEEDED、DAILYCAPEXCEEDED、RATELIMITED
- ACTIONDENIED
- SERVICENOTFOUND
- WALLETUNDERFUNDED