两种微支付流程:按请求付费和预付余额
无论您的代理按次付费还是预充值余额,网关都会自动处理发票创建、链上验证和上游代理。
按请求付费
客户端访问受保护端点并收到带发票的402。链上支付后使用X-Payment-Proof头重试。网关在Neutaro上验证交易并代理到上游。
预付余额
客户端通过/prepaid/deposit一次性存入NTMPI。后续请求包含X-Client-Id头,网关按次扣减——无需重复链上交易。
为AI代理和机器间商务而构建
机器间微支付层所需的一切,仅此而已。
链上验证
查询Neutaro REST API确认支付金额、备注和区块确认。
路由级定价
设置默认价格并通过GATEWAY_ROUTES按路由覆盖。便宜的读取,昂贵的写入。
管理API
用于内部钱包、交易和轻量级区块链账本的JWT保护端点。
反向代理
透明地将已认证请求转发到上游API。任何后端,任何语言。
SQLite存储
发票、预付余额和支付日志存储在单个本地文件中。零外部依赖。
Docker就绪
使用docker compose up一键部署。包含Ubuntu部署脚本。
网关API端点参考
用于健康检查、发票查询和余额查询的免费端点。其他请求通过402网关。
免费——无需支付
| 方法 | 路径 | 描述 |
|---|---|---|
| GET | /health | 带网关配置的健康检查 |
| GET | /invoices/:id | 检查发票状态(触发链上验证) |
| POST | /prepaid/deposit | 注册存款(先链上验证tx) |
| GET | /prepaid/balance/:clientId | 检查预付余额 |
管理——JWT保护
| 方法 | 路径 | 描述 |
|---|---|---|
| POST | /manage/auth/register | 注册管理员账户 |
| POST | /manage/auth/login | 登录,获取JWT令牌 |
| POST | /manage/wallet | 创建内部钱包 |
| GET | /manage/wallet | 列出您的钱包 |
| GET | /manage/wallet/:id | 按ID获取钱包 |
| POST | /manage/transactions | 创建内部交易 |
| GET | /manage/transactions/:id | 按ID获取交易 |
402网关——全局捕获
| 方法 | 路径 | 描述 |
|---|---|---|
| ANY | /* | 所有其他请求需要支付或预付余额 |
代理集成:Python和TypeScript示例
几行代码将402流程接入任何代理。网关处理发票和验证——您的代码只需支付和重试。
import requests, subprocess, os res = requests.get("http://gateway:4020/api/data") if res.status_code == 402: inv = res.json()["payment"] # Pay with ClawPurse subprocess.run([ "clawpurse", "send", inv["address"], inv["amount"], "--memo", inv["memo"], "--yes" ]) # Retry with proof res = requests.get( "http://gateway:4020/api/data", headers={"X-Payment-Proof": inv["invoiceId"]} ) data = res.json()
async function paidFetch(url: string) { let res = await fetch(url); if (res.status === 402) { const { payment } = await res.json(); // Pay with ClawPurse const { send, loadKeystore } = await import("clawpurse"); const { wallet, address } = await loadKeystore( process.env.CLAWPURSE_PASSWORD! ); await send( wallet, address, payment.address, payment.amount, { memo: payment.memo } ); // Retry with proof res = await fetch(url, { headers: { "X-Payment-Proof": payment.invoiceId } }); } return res.json(); }
不到一分钟安装并运行网关
# Clone and install git clone https://github.com/mhue-ai/clawpurse-gateway.git cd clawpurse-gateway && npm install # Configure cp .env.example .env # Set GATEWAY_PAYMENT_ADDRESS and JWT_SECRET # Start a test upstream npm run test:upstream # Start the gateway npm run dev # Test the 402 flow curl http://localhost:4020/api/test # Pay, then retry with proof: curl -H "X-Payment-Proof: <invoiceId>" \ http://localhost:4020/api/test
TypeScript微服务架构
精简的TypeScript代码库——网关逻辑、四个内部服务和中间件。46个单元测试覆盖每一层。
通过环境变量配置网关
所有设置通过环境变量或.env文件。
| 变量 | 默认值 | 描述 |
|---|---|---|
| PORT | 4020 | 网关监听端口 |
| GATEWAY_UPSTREAM | http://localhost:3000 | 代理的上游API |
| GATEWAY_PAYMENT_ADDRESS | — | 您的Neutaro钱包地址(必需) |
| GATEWAY_DEFAULT_PRICE | 0.001 | 每个请求的默认价格(NTMPI) |
| GATEWAY_ROUTES | — | 路由定价覆盖 |
| GATEWAY_REST | https://api2.neutaro.io | Neutaro REST API端点 |
| GATEWAY_MIN_CONFIRMATIONS | 1 | 所需区块确认数 |
| GATEWAY_INVOICE_TTL | 300 | 发票有效期(秒) |
| GATEWAY_PREPAID | false | 启用预付余额系统 |
| GATEWAY_DB | ./gateway.db | SQLite数据库路径 |
| JWT_SECRET | — | 管理API JWT密钥(必需) |
Timpi、Neutaro和ClawPurse生态系统的一部分
Ledger Timpi
Free NTMPI cost basis calculator and tax tool. Auto-fetches transfers, staking rewards, and node payouts from the Neutaro chain — calculates USD cost basis with FIFO/LIFO/HIFO and generates IRS Form 8949.
x402 Payment Protocol
Coinbase's open HTTP 402 standard routes every payment through a centralized facilitator that controls settlement. ClawPurse Gateway takes the opposite approach: peer-to-peer payments verified directly on Neutaro — no middleman, no EVM lock-in, no Coinbase SDK. Add prepaid balances for zero-latency repeat access, route-level pricing in one env var, and a full audit trail in SQLite. One Docker command to deploy; zero external dependencies to operate.
常见问题
什么是ClawPurse Gateway?
实现402 Payment Required状态码的开源HTTP反向代理,用NTMPI微支付保护任何API。支持按请求付费和预付余额流程。
HTTP 402支付流程如何工作?
客户端收到带发票的402响应,链上支付后使用X-Payment-Proof头重试。网关验证交易并代理到上游。
什么是NTMPI?如何获取?
NTMPI是Neutaro区块链的原生代币,是 Timpi 去中心化搜索网络的一部分。从 Timpi Drip水龙头获取免费NTMPI,或在 MEXC 通过NTMPI/USDT现货对购买,或通过Gravity Bridge桥接到Osmosis使用Keplr或Leap钱包兑换。
AI代理能否自主使用ClawPurse Gateway?
是的。网关为代理AI设计。代理程序化解析402发票,通过 ClawPurse钱包API链上支付并用支付证明头重试——完全无需人工干预。
请Mhue喝杯Timpi咖啡 ☕
如果网关为您节省了运维时间,给构建者打赏。
neutaro1e8xal8tqdegu4w48z3fphemd3hc07gech3pfek
备注可选——告诉我们您发布了什么!