16 KB. Zero dependencies.
Pure TypeScript protocol layer. No Sui SDK, no crypto libs bundled. Import the types, build your own stack.
The HTTP 402 protocol for Sui. One npm install. Five payment schemes. From one-shot payments to prepaid API budgets — 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 Sui 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 Sui integration for the how (PTB builders, signers, RPC calls).