This is the practical developer path. What is x402? is the concept and the technical deep dive is the protocol; here is how you actually wire it into an API, end to end, in about five minutes. It is stack-agnostic — the per-language specifics live on the SDK pages, which this guide links to rather than repeats.
The whole integration, in four steps
- Register a route + price. In the dashboard, add the route you want to monetise and its price, and issue a key. Start with a test key (
X402_ENV=sandbox). - Install the SDK for your stack. One package. There are nine official SDKs covering Node/Express, Next.js, Python (FastAPI and Django), PHP/Laravel, Go, Java/Spring Boot, C#/ASP.NET Core, and Ruby on Rails — see all SDKs and open the one for your stack for the exact install + snippet.
- Add one middleware. Wrap the route. It now answers unpaid requests with a signed price and only serves the result once payment is verified. You write no payment code.
- Go live. Swap the test key for a live key. No code change — it's an environment switch.
What the code looks like
Every SDK is the same shape: configure two environment variables and add one middleware. For example, in Express:
import express from "express";
import { x402 } from "@x402/express";
const app = express();
app.get("/premium", x402({ price: "0.10" }), (req, res) =>
res.json({ data: "paid content" }));
The equivalent for your stack — FastAPI decorator, Django/Rails/Laravel middleware, a Go http.Handler wrapper, a Spring Boot filter, ASP.NET Core middleware — is one line on the SDK page for that language. The signing is byte-identical across all nine (one frozen contract), so behaviour is the same wherever you run it.
Configuration
Two required environment variables — X402_API_KEY and X402_SECRET — plus optional X402_ENV (sandbox or production) and X402_BASE_URL. That's the entire configuration surface; the SDK reads them and the middleware does the rest.
Test mode is the safety net
With a sandbox key the full request → price → pay → verify → access loop runs with synthetic payments, so you can assert the integration in CI before any real money is involved. The SDK also fails closed: if the platform is unreachable it returns 502 and never serves paid content, so an outage can't leak a paid response.
Pick your SDK and go
Choose your stack on the SDKs page; each page has the exact install line, the minimal snippet, configuration, and an FAQ for that language. If you want the protocol details underneath, read the technical deep dive.
Next steps
- All SDKs · for developers
- Concept: What is x402? · Protocol: technical deep dive
- Ready: create an account