Build on layer402.
Pay, accept, and trust.

Everything you need to integrate layer402 into your own app - pay for APIs from an agent, charge for your own API, and read portable agent trust. Plus a full HTTP API reference.

Quickstart

live

What 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…UseStart here
Building an agent that consumes paid APIsThe Agent SDKQuickstart ↓ / Agent SDK
Selling an API and want to charge per callThe FacilitatorAccept payments
Either - and want portable reputationThe Trust RegistryTrust & identity

The payment loop

Every layer402 transaction is the same four-step loop. The SDK and facilitator handle every step for you.

flow
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

bash
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.

ts
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();
The DID is derived from your key automatically. Pass 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.