402, then proxies the request after payment and returns the backend’s response as a ResourceResponse.
Source: examples/ppr-standalone
What it demonstrates
proxyToonSellerConfigto enable standalone per-request gateway mode- Direct route calls for pay-per-use plus
/x402/accessfor 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 → DELIVEREDstate 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 aResourceResponse 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 withrouteId plus the concrete backend path they want to proxy:
ResourceResponse artifact.
MCP client flow
MCP clients (Claude Code, Cursor) call therequest_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.

