Metered API Marketplace
Provide a production-lean template for: OpenClaw Skill → Public API Endpoint → Usage Metering → Crypto Payment Gateway → BTC/ETH wallets.
This skill ships a runnable reference server (Fastify + SQLite) that:
- - Accepts structured JSON input
- Performs a high-value transformation (pluggable “transformers”)
- Returns structured JSON output
- Enforces signed API key auth
- Checks prepaid balance, deducts per call, and logs usage
- Accepts payment webhooks (Coinbase Commerce / BTCPay Server style)
- Applies a 2.5% platform fee in the ledger (fee addresses configurable)
Workflow (do this in order)
1) Pick the productized capability (the thing people pay for)
Choose ONE transformer that is:
- - high leverage (makes/keeps money)
- repeatable (called often)
- defensible (data, heuristics, workflow, or automation — not “generic summarization”)
Good defaults:
- - revenue/offer optimizer
- ad copy optimizer
- lead scoring
- contract risk flags
If unclear, start with the included revenue-amplifier transformer and replace it later.
2) Run the reference server locally
Use the bundled server in
scripts/server/.
Typical run:
- - INLINECODE2
- INLINECODE3
- INLINECODE4 and edit
- INLINECODE5
Set flat launch pricing in .env:
- -
COST_CENTS_PER_CALL=25 # $0.25/call
3) Create an API key
Use
scripts/server/admin/create_key_pg.js (or the admin HTTP endpoint) to create a key and starting balance.
4) Integrate from an OpenClaw skill / agent
Call the public endpoint with:
- - INLINECODE9
- INLINECODE10 (unix ms)
- INLINECODE11 =
hex(HMAC_SHA256(api_secret, ${timestamp}.${rawBody} INLINECODE13
5) Add real payments
Wire a payment processor webhook to
/v1/payments/webhook/:provider.
Providers are adapter-based:
- - start with “manual” credits (admin script)
- then add Coinbase Commerce or BTCPay Server
6) Ship
Deploy behind TLS (Cloudflare / Fly.io / Render / AWS / GCP). Put rate limiting at the edge + in-app.
Bundled resources
scripts/server/
Runnable reference implementation:
- - Fastify API server (long-running)
- Postgres ledger (balances, usage, credits)
- Signed API key auth
- Rate limiting + basic anti-abuse
- Webhook endpoint(s)
scripts/nextjs-starter/
Vercel-ready Next.js API implementation:
- - Serverless API routes (no
listen()) - Postgres ledger (Supabase Transaction Pooler recommended)
- Same auth + pricing + webhook concepts
references/
Read only when needed:
- -
references/api_reference.md – endpoint contracts + auth/signing - INLINECODE17 – pricing, fee logic, idempotency
- INLINECODE18 – provider adapters (Coinbase/BTCPay patterns)
计量API市场
提供一个生产精简模板,用于:OpenClaw技能 → 公共API端点 → 使用计量 → 加密支付网关 → BTC/ETH钱包。
该技能附带一个可运行的参考服务器(Fastify + SQLite),具备以下功能:
- - 接受结构化JSON输入
- 执行高价值转换(可插拔的转换器)
- 返回结构化JSON输出
- 强制签名API密钥认证
- 检查预付费余额,按调用扣费,并记录使用情况
- 接受支付Webhook(Coinbase Commerce / BTCPay Server风格)
- 在账本中应用2.5%平台费用(费用地址可配置)
工作流程(按顺序执行)
1) 选择产品化能力(用户付费的功能)
选择一个转换器,需满足:
- - 高杠杆(创造/保持收入)
- 可重复(频繁调用)
- 可防御(数据、启发式算法、工作流或自动化——而非通用摘要)
推荐默认选项:
- - 收入/报价优化器
- 广告文案优化器
- 潜在客户评分
- 合同风险标记
如果不确定,先使用内置的revenue-amplifier转换器,后续再替换。
2) 本地运行参考服务器
使用scripts/server/中的捆绑服务器。
典型运行方式:
- - cd scripts/server
- npm install
- cp .env.example .env并编辑
- npm run dev
在.env中设置统一启动定价:
- - COSTCENTSPER_CALL=25 # $0.25/次调用
3) 创建API密钥
使用scripts/server/admin/create
keypg.js(或管理HTTP端点)创建密钥和初始余额。
4) 从OpenClaw技能/代理集成
调用公共端点时需提供:
- - x-api-key
- x-timestamp(Unix毫秒)
- x-signature = hex(HMACSHA256(apisecret, ${timestamp}.${rawBody}))
5) 添加真实支付
将支付处理器Webhook连接到/v1/payments/webhook/:provider。
提供商基于适配器模式:
- - 从手动积分开始(管理脚本)
- 然后添加Coinbase Commerce或BTCPay Server
6) 部署
在TLS后面部署(Cloudflare / Fly.io / Render / AWS / GCP)。在边缘层和应用内设置速率限制。
捆绑资源
scripts/server/
可运行的参考实现:
- - Fastify API服务器(长期运行)
- Postgres账本(余额、使用量、积分)
- 签名API密钥认证
- 速率限制 + 基本防滥用
- Webhook端点
scripts/nextjs-starter/
Vercel就绪的Next.js API实现:
- - 无服务器API路由(无listen())
- Postgres账本(推荐使用Supabase事务连接池)
- 相同的认证 + 定价 + Webhook概念
references/
按需阅读:
- - references/apireference.md – 端点合约 + 认证/签名
- references/billingledger.md – 定价、费用逻辑、幂等性
- references/providers.md – 提供商适配器(Coinbase/BTCPay模式)