What is Stellar x402 Gateway?
Stellar x402 Gateway is an open-source payment infrastructure suite that implements the HTTP 402 Payment Required standard for the Stellar blockchain. x402-stellar is an API infrastructure suite. It is neither solely a web app nor solely a CLI tool, but rather a set of developer building blocks:- A Soroban Smart Contract (
gateway-contract): Runs on the Stellar blockchain to verify cryptographic payment proofs, prevent replays, and split revenue between merchants and the protocol. - Middleware SDKs (
@stellar-x402/express,@stellar-x402/fastify,@stellar-x402/client,@stellar-x402/facilitator,@stellar-x402/streaming): Code libraries that backend developers import directly into their Node.js or TypeScript APIs to paywall routes, meter token streams, or sponsor gas fees with a single line of code. - A Standalone Reverse Proxy Daemon (
proxy/in Go): A lightweight CLI daemon and binary (similar to Nginx or Envoy) that runs in front of backends written in any language (Python FastAPI, Go, Rust, Java). It intercepts incoming HTTP traffic, returns HTTP 402 challenges when unpaid, and forwards paid requests to the upstream server. - A Merchant Web Dashboard (
apps/webin Next.js 15): A browser-based management interface where API providers monitor revenue, inspect settled transactions on Stellar, and configure route pricing.
payment-signature header, the request is verified and forwarded to the backend API.
The Problem It Solves
Traditional API monetization relies on credit cards, monthly subscriptions, API key quotas, and invoice cycles. This model fails in three critical scenarios:- Autonomous AI Agents: AI agents cannot open bank accounts, solve CAPTCHAs, or negotiate enterprise billing contracts. They need machine-to-machine, per-request payments settled directly in digital dollars (USDC).
- Micro-transaction Friction: Credit card processing incurs a 2.9% + 0.005 or $0.01.
- Complex Integration Overhead: Building on-chain billing from scratch requires writing custom smart contracts, managing nonces, parsing XDRs, and handling replay protection.
How x402 Solves It
- Sub-Cent Economics: Built on Stellar, where transaction fees are fractions of a cent ($0.00001) and ledger closes occur in 3 to 5 seconds.
- Zero Backend Overhaul: Middleware for Express and Fastify, plus a standalone Go reverse proxy that runs in front of Python, Go, Rust, or Ruby APIs without changing existing application code.
- On-Chain Cryptographic Settlement: Powered by a Soroban smart contract that enforces monotonic replay protection, verifies signatures, and distributes protocol and merchant fees in a single atomic transaction.
- Client Auto-Payer SDK: A lightweight client library that intercepts 402 challenges, checks caller-defined budget caps, signs payments, and retries requests automatically.