Skip to main content
This guide walks through adding x402 payment middleware to your server so clients must pay to access your endpoints.
  • A wallet address to receive payments
  • An existing HTTP API built with Express, Next.js, Hono, Gin, FastAPI, or Flask
  • Node.js 18+, Go 1.21+, or Python 3.10+

1. Install dependencies

2. Add payment middleware

Wrap your paid routes with x402 middleware and point it at the Abstract facilitator.

3. Shape the paid resource

For agent-facing APIs, define:
  • a stable route
  • a clear description
  • a deterministic response format
  • a price that is cheap enough for repeated automated use

4. Test the flow

The protected route should:
  1. return 402 Payment Required when called without payment
  2. advertise the payment requirements in the response
  3. return 200 once the client retries with a valid payment

Next

  • Continue to Make x402 Payments to test a paying client
  • Compare with MPP if you expect repeated micro-payments