All work
Go // Payments

Nexus402

A clearinghouse for AI agents — one API key and a prepaid wallet to call any paid MCP tool. The gateway verifies, meters, and forwards every call, and fails closed when it can't be sure it got paid.

Highlight
250 architecture decision records · fail-closed by design
Role
Co-creator & engineer
Status
Live
Year
2026
Built with
Pradip Dhungana
Stack
GoRedisPostgreSQLAWS SQSAWS S3StripeDockerKubernetes

The problem

AI agents increasingly call tools over MCP, and some of those tools cost money to run. Today every tool creator has to build their own keys, billing, and abuse protection, and every developer has to sign up separately for each one.

Nexus402 sits in the middle. Developers prepay a single wallet and call any published tool with one key — no SDK, just the HTTP client they already use. Creators host their own MCP server and publish a fixed price per tool version. When a wallet can't cover a call, the gateway answers with HTTP 402 Payment Required.

How a call flows

  1. Agent → gateway. The gateway verifies the API key, looks up the price for that exact tool version, and runs a single Redis Lua script that checks the balance and the 24-hour spend cap and deducts the price atomically.
  2. Gateway → queue. It publishes a charge event to AWS SQS and waits for the publish to succeed before contacting the creator.
  3. Gateway → creator. The request is signed with Ed25519 inside a short validity window, passes an SSRF guard, and the response streams back to the agent.
  4. Queue → worker. Every five minutes a worker writes balanced double-entry totals per wallet, tool, and period into PostgreSQL, and per-charge records to S3 as Parquet.
  5. Reconciliation. A separate read-only tool compares Redis, the queue, PostgreSQL, and the wallet cache, and reports any disagreement.

Key decisions

Redis meters, PostgreSQL decides. Redis approves and meters spending on the hot path, but a charge isn't money until the five-minute total commits to PostgreSQL. That keeps the database out of the request path without making the cache the source of truth.

Fail closed. If Redis or the queue is unavailable, the call gets a 503 and is never forwarded unpaid. An outage costs availability, never money.

An append-only ledger. No UPDATEs or DELETEs: corrections are new reversing entries, every journal entry sums to zero, and duplicate submissions are rejected by unique idempotency keys.

No floats near money. Every amount is an int64 count of micro-dollars and travels over the wire as a string. Published prices are immutable — a new price means a new tool version.

Payouts need several independent switches. Creator payouts recompute the amount from the journal, refuse to run if the cache and journal disagree, and live payouts also need a daily cap.

Where it stands

Nexus402 is live at nexus402.dev. End to end, it has been measured at about 210 requests per second from outside AWS, with most of the time spent on the network rather than in the gateway.

I built it with Pradip Dhungana over ten weeks, working with AI coding agents, and we recorded 250 architecture decision records along the way. I'm writing up what that process taught us about where AI-written code needs human safeguards. You can follow the launch at nexus402.dev.