Skip to content

s402Your AI agent needs to pay for things.

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.

Abstract visualization of digital payment flowing through a network

See It in Action

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.

typescript
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).

Released under the MIT License.