Private payments
for AI agents.

Agents pay for APIs in shielded Zcash: one deposit, then a signed voucher per call.

Install

npm install @z402-net/client
Shielded by default.
A viewing key reveals it.

02How it works

Pay once on-chain. Then every call is a signed voucher.

Paying on chain for every call would be slow and public. Only deposits touch the chain here, and they are shielded.

  1. 402llm.example
    {  "scheme": "prepaid-voucher",  "network": "zcash:mainnet",  "amount": "500",  "asset": "ZEC",  "extra": {    "windowZat": "100000",    "creditRatioBps": 2500  }}

    01 402

    Confirmed deposits also earn 25% credit, up to 200,000 zat. The stock x402 client reads all of it from the 402, so there is no account and no API key.

    The API answers 402 with its terms: 500 zat a call, prepaid in 100,000-zat windows (200 calls).

  2. D1ShieldedConfirmed

    With viewing key

    Value
    100,000 zat
    Memo
    <session key>:1

    On chain

    Value
    hidden
    Memo
    hidden

    02 Deposit

    A viewing key held by the facilitator reads the deposit. The first call is served on it before it confirms.

    The agent pays one window, shielded, with its session key in the memo. Nothing on chain shows the amount or the merchant.

  3. VoucherSigned
    {  "sessionKey": "7c1e…9d",  "cumulativeZat": "1500",  "sig": "e04b…3a"}
    #001 200  c=500  limit=125,000#002 200  c=1,000  limit=125,000#003 200  c=1,500  limit=125,000

    03 Voucher

    No transaction per call: only deposits touch the chain.

    Each call carries the running total, signed with the session key. The facilitator checks it and the call returns at HTTP speed.

  4. Limit225,000 zat
    Confirmed
    100,000
    Pending
    100,000
    Credit
    25,000

    No second depositlimit 125,000

    #251 402 z402_deposit_required

    04 Credit

    The next deposit goes out in the background once headroom falls under one window, so the stream never stalls. Unconfirmed money counts for one window at most.

    The limit is confirmed + pending + 25% credit, and the next deposit leaves before it is reached. An agent that stops depositing is refused at its limit.

03Services

Live services. Each one priced per call.

Every row is a paid API that answers 402 with its terms. Agents read the same list from the facilitator's Bazaar.

04Get started

Keep the stock x402 client. Register one more scheme.

The rest of the agent's fetch loop does not change. Run the stack to pay the four starter services from your own machine.

agent.ts
import { x402Client, wrapFetchWithPayment } from "@x402/fetch";import { zcashClientScheme } from "./zcash"; // a PrepaidVoucherScheme from @z402-net/client const client = new x402Client();client.register("zcash:mainnet", zcashClientScheme);const paidFetch = wrapFetchWithPayment(fetch, client); await paidFetch("https://llm.example/v1/generate", {  method: "POST",  headers: { "content-type": "application/json" },  body: JSON.stringify({ prompt: "Write a haiku about privacy." }),});

Run the stack

docker compose up -d

Pay every service

docker compose run --rm smoke