360 Secure SkillHub
360 安全技能中心

x402-api-builder

这是帮助开发者将自有数据/服务转化为付费API的工具,核心含FastAPI模板、x402发现清单、USDC链上支付流程、权限校验及MCP包装器。典型场景为开发者变现数据/服务,用户支付USDC获API密钥调用,支持多定价模式。输入需添加自定义端点、配置环境变量,输出可运行的付费API服务,链上验证保障安全。

northcap-group
热度 33.03
最近更新 2026-08-21 22:22:58
分类:开发依赖:代码执行 / 读写文件 / 第三方 API / MCP 服务应用场景:代码生成 / API 集成 / DevOps / 模板

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add x402-api-builder
Metadata
name
x402-api-builder
description
Build your own pay-per-call API with the x402 standard: FastAPI + payment manifest + API keys + MCP wrapper. Sell your data/services per call (USDC). Template with ON-CHAIN payment verification (secure-by-default).
metadata
{"x402-api-builder":{"requires":{"python3":true,"network":["https://mainnet.base.org","https://api.telegram.org"],"env":["PAYMENT_RPC_URL","X402_BASE"],"files":["api_keys.json"]}}}

X402 API Builder 💳🔌

Turn your data/service into a paid pay-per-call API in under an hour.

What you get

  1. FastAPI server with paid endpoints (template)
  2. x402 manifest (/.well-known/x402) — so other agents can discover you
  3. Payment flow: customer pays USDC → sends txHash → gets API key
  4. 401/402 gates — no free calls
  5. MCP wrapper — your API as MCP tools (get_signals, get_market, etc.)

Quick start

# 1) Install
pip install fastapi uvicorn

# 2) Copy the template
cp scripts/server.py .
cp scripts/mcp_server.py .

# 3) Add YOUR endpoints (see TODO in server.py)
# 4) Run
uvicorn server:app --host 0.0.0.0 --port 8791 &

# 5) Verify manifest
curl http://YOUR_IP:8791/.well-known/x402

Pricing (recommended)

Product Price
Per call $0.005 (market: $0.001-0.01)
Monthly (unlimited) $25
Premium (live + alerts) $100
Enterprise (SLA + white-label) $500

Security (critical)

  • On-chain verification (secure-by-default): /v1/purchase only issues an API key after the txHash is verified on-chain (eth_getTransactionByHash + receipt status against Base RPC). Unreachable RPC or invalid tx = purchase denied (402).
  • Never commit api_keys.json (gitignore it!)
  • API key = HMAC of txHash (verifiable, not guessable)
  • 401 without key · 402 when call usage is exhausted or payment is not verified
  • Client: refuses to send the key over plain HTTP to non-local hosts (use X402_BASE=https://...)
  • Rate-limit per key

Files

x402-api-builder/
├── SKILL.md
└── scripts/
    ├── server.py      # FastAPI template (manifest + purchase + gates)
    ├── mcp_server.py  # MCP wrapper (fastmcp)
    └── client.py      # Test client