HTTP 402 · Payment Required

Teach your agents to pay.

local402 drops a payment wall in front of any local server or MCP tool — so you can test paying AI agents with no wallet, no chain, and no real money.

$ npx local402 --target http://localhost:3000 --price 0.001
MIT licensed Zero config Simulated by default
local402 — paywall demo
Request header x-payment
not sent
The problem

Testing a paying agent shouldn't cost you a payment stack.

You just want to check that your agent notices a 402 and retries with payment. That shouldn't mean funding a testnet wallet every run.

✕ The hard way

Stand up a facilitator, fund a testnet wallet, wait on-chain, and untangle payment logic from your app — every single test run. Reproducing the "unpaid" path is its own chore.

✓ With local402

One reverse proxy in front of your server. Instant, deterministic 402s. Point your agent at it and watch it learn to pay. Tear it down just as fast.

How it works

Pay first, then pass through.

local402 is a tiny reverse proxy with one opinion. It sits between your agent and your server and checks a single header.

Client
agent / curl
sends request
──▶
Paywall
local402
:4020
──▶
Origin
your server
:3000
✕ No x-payment header
→ 402 Payment Required, with a helpful JSON body and payment headers.
✓ x-payment: simulated
→ proxied to your target; the real response comes back untouched.
What you get

Small tool, sharp edges.

Simulated by default

No blockchain, no wallets, no waiting. Instant, deterministic 402s you can build against offline.

One command

npx local402 and you're guarding a server. Nothing to install, nothing to configure.

Any HTTP or MCP tool

If it speaks HTTP, local402 can wall it. Drop it in front of an API, a webhook, or an MCP server.

x402-shaped responses

Real 402 bodies and headers your client can parse, plus a simulated settlement receipt on paid calls.

Free status route

/__local402 stays open and unpaywalled, so you can health-check the proxy any time.

Yours to bend

MIT-licensed, tiny, one dependency. Fork it, tweak the pricing logic, ship your own.

Quick start

Running in under a minute.

You don't even need to install it — npx fetches it fresh.

STEP 01

Run your server

Any local API or MCP tool. Say it's listening on port 3000.

$ node server.js
STEP 02

Raise the paywall

Point local402 at it. It listens on :4020 by default.

$ npx local402 --target http://localhost:3000
STEP 03

Send your agent to :4020

Unpaid gets a 402. Add the header and it's proxied through.

$ curl :4020 -H "x-payment: simulated"
Roadmap

Simple on purpose — growing on demand.

v0.1
Simulated mode Shipped
Instant, local, blockchain-free 402 paywall. Available now on npm.
v0.2
Real x402 settlement Next
Verify actual X-PAYMENT payloads through a pluggable facilitator.
v0.3
MCP-native mode Planned
First-class paywalling for MCP tools and resources, not just HTTP.
v0.4
Per-route pricing Planned
Different prices for different paths and methods.
v0.5
Usage dashboard Planned
A live terminal view of requests, payments, and revenue.
Ready when your agents are

Put a price on it.

One command stands between your agent and its first 402. Go find out if it pays up.

$ npx local402 --target http://localhost:3000 --price 0.001