Why pay402
HTTP 402 “Payment Required” is how the web signals that an endpoint costs money, but there's no standard way to handle it. pay402 bridges that gap.
AI agents and automated pipelines can pay for API access on their own, no human in the loop. Built-in spend limits keep budgets safe.
L402 (Lightning) and x402 (USDC on Base & Solana) are competing standards. pay402 supports both so your code doesn't need to pick one.
Per-request caps, hourly rolling windows, and daily budgets. URL allowlists and dry-run mode. Ship agents that spend real money with confidence.
import { fromEnv } from "pay402";const client = fromEnv();const res = await client.fetch( "https://api.example.com/premium-data");const data = await res.json();Capabilities
Replace fetch with pay402 and every 402 response is handled automatically. Parse, pay, retry, cache. Zero boilerplate.
Lightning Network (L402) and USDC on Base or Solana (x402). One SDK, both protocols, automatic rail selection.
Per-request, hourly, and daily limits. URL allowlists and denylists. Dry-run mode. Built for autonomous agents that spend real money.
Payment proofs are cached and reused automatically. No double-paying for the same endpoint within the token's TTL.
Gate your API routes behind 402 payments. Multi-rail challenge headers, proof verification, and payment callbacks built in.
Wrap MCP server tools with payment gates. No changes to tool implementations. The wrapper handles challenges and proof verification.
Under the Hood
The SDK intercepts 402 responses, selects the optimal payment rail, executes payment, and retries with proof. All in one round-trip.
Bitcoin Lightning Network with Macaroon authentication. Pay BOLT11 invoices, receive preimage proofs. Sub-second settlement.
Stablecoins on Base and Solana. EIP-3009 signed authorizations or direct SPL token transfers. Dollar-denominated pricing.