Tiny. Zero dependencies. Multi-language.
TypeScript (~30 KB) and Python implementations. No Sui SDK, no crypto libs bundled. Import the types, build your own stack.
Chain-agnostic HTTP 402 payment protocol. Five payment schemes. TypeScript and Python implementations — built for agents that spend money autonomously.

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).
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.2.3 · Five payment schemes · 868 tests across TypeScript and Python · 132-vector conformance suite · Apache-2.0 · npm