Two micropayment flows: pay-per-request and prepaid balance
Whether your agent pays per call or pre-funds a balance, the gateway handles invoice creation, on-chain verification, and upstream proxying automatically.
Pay-per-request
Client hits a gated endpoint and receives a 402 with an invoice.
It pays on-chain, then retries with an X-Payment-Proof header.
The gateway verifies the transaction on Neutaro and proxies the request upstream.
Prepaid balance
Client deposits NTMPI once via /prepaid/deposit.
Subsequent requests include an X-Client-Id header
and the gateway deducts from the balance per call — no repeated on-chain transactions.
Built for AI agents and machine-to-machine commerce
Everything a machine-to-machine micropayment layer needs, nothing it doesn’t.
On-chain verification
Queries Neutaro REST API to confirm payment amount, memo, and block confirmations before allowing access.
Route-level pricing
Set a default price and override per-route with GATEWAY_ROUTES. Cheap reads, expensive writes.
Management API
JWT-protected endpoints for internal wallets, transactions, and a lightweight blockchain ledger.
Reverse proxy
Transparently forwards authenticated requests to your upstream API. Any backend, any language.
SQLite storage
Invoices, prepaid balances, and payment logs stored locally in a single file. Zero external dependencies.
Docker-ready
One-command deploy with docker compose up. Ubuntu deploy script included for bare metal.
Gateway API endpoint reference
Free endpoints for health checks, invoice lookups, and balance queries. Everything else goes through the 402 gate.
Free — no payment required
| Method | Path | Description |
|---|---|---|
| GET | /health | Health check with gateway config |
| GET | /invoices/:id | Check invoice status (triggers on-chain verification) |
| POST | /prepaid/deposit | Register a deposit (verifies tx on-chain first) |
| GET | /prepaid/balance/:clientId | Check prepaid balance |
Management — JWT protected
| Method | Path | Description |
|---|---|---|
| POST | /manage/auth/register | Register admin account |
| POST | /manage/auth/login | Login, get JWT token |
| POST | /manage/wallet | Create internal wallet |
| GET | /manage/wallet | List your wallets |
| GET | /manage/wallet/:id | Get wallet by ID |
| POST | /manage/transactions | Create internal transaction |
| GET | /manage/transactions/:id | Get transaction by ID |
402 Gate — catch-all
| Method | Path | Description |
|---|---|---|
| ANY | /* | All other requests require payment or prepaid balance |
Agent integration: Python and TypeScript examples
Wire the 402 flow into any agent in a few lines. The gateway handles invoicing and verification — your code just needs to pay and retry.
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(); }
Install and run the gateway in under a minute
# 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 microservice architecture
A focused TypeScript codebase — gateway logic, four internal services, and middleware. 46 unit tests cover every layer.
Gateway configuration via environment variables
All settings via env vars or .env file.
| Variable | Default | Description |
|---|---|---|
| PORT | 4020 | Gateway listen port |
| GATEWAY_UPSTREAM | http://localhost:3000 | Upstream API to proxy |
| GATEWAY_PAYMENT_ADDRESS | — | Your Neutaro wallet address (required) |
| GATEWAY_DEFAULT_PRICE | 0.001 | Default price per request in NTMPI |
| GATEWAY_ROUTES | — | Route pricing overrides |
| GATEWAY_REST | https://api2.neutaro.io | Neutaro REST API endpoint |
| GATEWAY_MIN_CONFIRMATIONS | 1 | Block confirmations required |
| GATEWAY_INVOICE_TTL | 300 | Invoice validity in seconds |
| GATEWAY_PREPAID | false | Enable prepaid balance system |
| GATEWAY_DB | ./gateway.db | SQLite database path |
| JWT_SECRET | — | Secret for management API JWT (required) |
Part of the Timpi, Neutaro & ClawPurse ecosystem
ClawPurse Wallet
The local NTMPI wallet with encrypted keystores, guardrails, staking, and destination allowlists. The reference client for paying through the gateway.
Neutaro Blockchain
The Cosmos SDK chain powering NTMPI. All gateway payments are verified directly against Neutaro’s REST API — no oracles, no bridges.
Timpi Network
Privacy-first decentralised search with an open Data API and DePIN nodes. ClawPurse Gateway lets you monetise any Timpi-powered service via micropayments.
Frequently asked questions
What is ClawPurse Gateway?
An open-source HTTP reverse proxy that implements the 402 Payment Required status code to gate any API behind NTMPI micropayments on the Neutaro blockchain. It supports pay-per-request and prepaid balance flows for AI agents, automation scripts, and machine-to-machine commerce.
How does the HTTP 402 payment flow work?
A client requests a gated endpoint and receives a 402 response with an invoice containing an invoiceId, amount, address, and memo. The client pays on-chain using ClawPurse or any Neutaro wallet, then retries the request with an X-Payment-Proof header. The gateway verifies the transaction on Neutaro and proxies the request upstream.
What is NTMPI and how do I get it?
NTMPI is the native token of the Neutaro blockchain, part of the Timpi decentralised search network. You can acquire NTMPI on MEXC via the NTMPI/USDT spot pair, or bridge through Gravity Bridge to Osmosis and swap using Keplr or Leap wallet.
Can AI agents use ClawPurse Gateway autonomously?
Yes. The gateway is designed for agentic AI and machine-to-machine workloads. Agents can programmatically parse the 402 invoice, pay on-chain via the ClawPurse wallet API, and retry with the payment proof header — all without human intervention.
Buy Mhue a Timpi coffee ☕
If the gateway is saving your stack ops time, tip the builders.
neutaro1e8xal8tqdegu4w48z3fphemd3hc07gech3pfek
Memo optional — just let us know what you shipped!