Quickstart
liveWhat is layer402?
layer402 is a payment layer for AI agents built on the x402 standard. It lets an agent pay for an API call automatically when the server answers with HTTP 402, verifies and settles that payment on-chain, and attaches a portable trust score to every agent so providers know who they are transacting with.
There are two sides, and you can adopt either independently:
| You are… | Use | Start here |
|---|---|---|
| Building an agent that consumes paid APIs | The Agent SDK | Quickstart ↓ / Agent SDK |
| Selling an API and want to charge per call | The Facilitator | Accept payments |
| Either - and want portable reputation | The Trust Registry | Trust & identity |
The payment loop
Every layer402 transaction is the same four-step loop. The SDK and facilitator handle every step for you.
pay → agent signs an x402 payment when it gets a 402 response verify → facilitator checks signature, replay, balance, and trust settle → payment is settled on-chain and a signed receipt is returned score → the agent's trust score is updated from the settled payment
Install the SDKlive
npm install @fourotwo/agent-sdk # TypeScript / JavaScript pip install fourotwo-agent-sdk # Python
Make a paid request
The agent is a drop-in fetch replacement. Point it at any x402-gated URL and it handles the 402 → sign → retry handshake transparently.
import { fourotwoAgent } from '@fourotwo/agent-sdk';
const agent = new fourotwoAgent({
privateKeyHex: process.env.FOUROTWO_PRIVATE_KEY, // never leaves your process
budget: { dailyTokens: 10, perRequestTokens: 0.5 }, // optional spend limits (whole tokens)
});
// agent.fetch behaves exactly like fetch - but pays when it has to
const res = await agent.fetch('https://api.example.com/data/RE-NYC-001');
const data = await res.json();did explicitly only if you registered the agent under a specific identity. Your private key is used to sign locally and is never transmitted.Try it without writing code
The Playground crafts a real signed Casper payment and runs it through the live facilitator so you can watch the verify → settle trace and the signed receipt before integrating.