Skip to main content
v0.2.0 — open source on GitHub

ClawPurse
402 Gateway

An HTTP reverse proxy that gates any API behind NTMPI micropayments on the Neutaro blockchain. Pay-per-request and prepaid balance flows for AI agents, automation scripts, and machine‑to‑machine commerce.

  Client (AI agent, script, browser)
    │
    ├── GET /api/data ─────────────────────▶  402 Gateway
    │                                              │
    │   ◀── 402 Payment Required ────────────────┘
    │       { invoiceId, amount, address, memo }
    │
    ├── clawpurse send <address> <amount> --memo <memo> --yes
    │       (on-chain NTMPI payment)
    │
    ├── GET /api/data ─────────────────────▶  402 Gateway
    │   Header: X-Payment-Proof: <invoiceId>     │
    │                                              │
    │   Gateway verifies payment on Neutaro    │
    │                                              │
    │   ◀── 200 OK (proxied from upstream) ────┘
Payment Flows

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.

1

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.

2

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.

Capabilities

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.

API

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

MethodPathDescription
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

MethodPathDescription
POST/manage/auth/registerRegister admin account
POST/manage/auth/loginLogin, get JWT token
POST/manage/walletCreate internal wallet
GET/manage/walletList your wallets
GET/manage/wallet/:idGet wallet by ID
POST/manage/transactionsCreate internal transaction
GET/manage/transactions/:idGet transaction by ID

402 Gate — catch-all

MethodPathDescription
ANY /* All other requests require payment or prepaid balance
Integration

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.

agent.py
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()
agent.ts
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();
}
Quick Start

Install and run the gateway in under a minute

terminal
# 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
Architecture

TypeScript microservice architecture

A focused TypeScript codebase — gateway logic, four internal services, and middleware. 46 unit tests cover every layer.

config.ts
Env-driven gateway config
db.ts
SQLite: invoices, prepaid, logs
invoice.ts
Invoice creation & route pricing
verify.ts
On-chain payment verification
proxy.ts
Reverse proxy to upstream
AuthService
JWT auth for management API
WalletService
Internal wallet ledger
TxService
Wallet-to-wallet transfers
BlockchainSvc
Internal block chain
Config

Gateway configuration via environment variables

All settings via env vars or .env file.

VariableDefaultDescription
PORT4020Gateway listen port
GATEWAY_UPSTREAMhttp://localhost:3000Upstream API to proxy
GATEWAY_PAYMENT_ADDRESSYour Neutaro wallet address (required)
GATEWAY_DEFAULT_PRICE0.001Default price per request in NTMPI
GATEWAY_ROUTESRoute pricing overrides
GATEWAY_RESThttps://api2.neutaro.ioNeutaro REST API endpoint
GATEWAY_MIN_CONFIRMATIONS1Block confirmations required
GATEWAY_INVOICE_TTL300Invoice validity in seconds
GATEWAY_PREPAIDfalseEnable prepaid balance system
GATEWAY_DB./gateway.dbSQLite database path
JWT_SECRETSecret for management API JWT (required)
Ecosystem

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.

github.com/mhue-ai/ClawPurse →

Neutaro Blockchain

The Cosmos SDK chain powering NTMPI. All gateway payments are verified directly against Neutaro’s REST API — no oracles, no bridges.

neutaro.com →

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.

timpi.io →

FAQ

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.