Superset of x402 and MPP
Speaks x402 V1/V2 and MPP as payment-in formats, plus five schemes they structurally can't express. An agent that picks s402 gets every option the others offer, plus the ones they don't.
The chain-agnostic HTTP 402 protocol for AI agents. Superset of x402 and MPP — same price or cheaper where they overlap, six payment schemes where they can't. TypeScript, Python, Go.

An AI agent hits a paid API. The server says "pay me." The agent pays and gets the data. Three HTTP requests, zero human intervention.
import {
extractRequirementsFromResponse,
encodePaymentPayload,
S402_HEADERS,
} from 's402';
async function agentFetch(url: string, buildPayment: PaymentBuilder) {
const res = await fetch(url);
if (res.status !== 402) return res;
// 1. Decode what the server wants
const requirements = extractRequirementsFromResponse(res);
if (!requirements) throw new Error('Invalid 402 response');
// 2. Build and sign a payment (you bring the chain SDK)
const payment = await buildPayment(requirements);
// 3. Retry with payment attached
return fetch(url, {
headers: { [S402_HEADERS.PAYMENT]: encodePaymentPayload(payment) },
});
}s402 defines the wire format — what gets sent over HTTP. You bring your own chain SDK for the how (PTB builders, signers, RPC calls).
🤖 I'm building an AI agent Need to pay for APIs, tools, or inference. Start with the Quick Start to wire a client in 5 minutes, then read Which Scheme Do I Need? to pick between Exact, Upto, and Prepaid.
🏗 I run a paid API Want agents to pay you directly — no billing dashboards, no API keys. See the server tutorial for a 402 endpoint in 20 lines, then Fee Ownership & Trust for who pays gas.
🦊 I build a wallet or SDK Need to speak s402 from a client library. Start with the Wire Format Spec and the 161-vector conformance suite. TypeScript, Python, Go adapters exist today.
⚙️ I operate a facilitator Running verify/settle infra for a chain or scheme. Read the Architecture page for the facilitator contract, then Security Model for invariants you must preserve.
🔎 I'm auditing or researching Evaluating s402 for production or academic work. Start with the Whitepaper, Threat Model, and the three-way comparison against x402 and MPP.
🔁 I'm migrating from another protocol Already running x402 or MPP. See Migrating from x402 (one-line middleware swap) or Migrating from MPP (coexistence pattern, no rip-and-replace).
import httpx
from s402 import decode_payment_required, encode_payment_payload, S402_HEADERS
url = "https://api.example.com/premium-data"
res = httpx.get(url)
if res.status_code == 402:
requirements = decode_payment_required(res.headers[S402_HEADERS["PAYMENT_REQUIRED"]])
payment = build_payment(requirements) # you bring the chain SDK
res = httpx.get(url, headers={S402_HEADERS["PAYMENT"]: encode_payment_payload(payment)})pip install s402 # Python — zero dependencies
npm install s402 # TypeScript — zero dependenciesv0.5.0 · Six payment schemes · 831 tests · 161-vector conformance suite · Apache-2.0 · npm