Skip to main content
A two-process setup: a Key0 payment gateway (port 3000) in front of a backend API (port 3001). Clients never talk to the backend directly — they call the gateway route they want to buy, Key0 returns a 402, then proxies the request after payment and returns the backend’s response as a ResourceResponse. Source: examples/ppr-standalone

What it demonstrates

  • proxyTo on SellerConfig to enable standalone per-request gateway mode
  • Direct route calls for pay-per-use plus /x402/access for subscription token purchases
  • Automatic payment header injection (x-key0-tx-hash, x-key0-plan-id, x-key0-amount) so the backend can log/audit payments
  • A shared secret (x-gateway-secret) that the backend uses to reject requests that bypass the gateway
  • Full HTTP, A2A, and MCP client support with no separate route registrations needed
  • PENDING → PAID → DELIVERED state transitions with refund safety when the backend returns non-2xx

Architecture

Key differences from embedded mode

Running locally

Prerequisites

  • Bun v1.3+ or Node 18+
  • Redis running locally
  • A wallet address on Base Sepolia
  • A gas wallet private key (ETH-funded) for settlement

Setup

Environment variables

Code walkthrough

1. Enable proxy mode with proxyTo

2. Client request (HTTP)

3. ResourceResponse shape

4. Backend receives payment headers

The backend receives these headers on every proxied request:

5. Non-2xx backend response

If the backend returns 4xx/5xx, Key0 wraps it in a ResourceResponse and the challenge stays in PAID state. The refund cron will process it:

A2A client flow

A2A agents discover the same route catalog and request access with routeId plus the concrete backend path they want to proxy:
After settlement, the executor returns a completed task with a ResourceResponse artifact.

MCP client flow

MCP clients (Claude Code, Cursor) call the request_access tool with routeId and a resource field. Set mcp: true in SellerConfig to enable:

Next Steps

PPR Embedded Example

Per-request with Key0 inside your application.

SellerConfig: proxyTo

ProxyToConfig, FetchResourceParams, and FetchResourceResult types.

POST /x402/access

Full API reference for the unified payment endpoint.

Two Modes

When to use standalone vs. embedded.