Menu

Explorer & Settings

Tempo Explorer Submit Project
🧰 SDKs & Examples

x402 SDKs & Libraries

The libraries to add x402 payments to your code — by language. Curated real projects, live GitHub stars.

Diagram showing the x402 SDK working across TypeScript, Python, Go and Rust: each language calls a single paymentMiddleware() that gates a paid route requiring USDC payment

The x402 flow in one glance

# 1. Client requests a protected resource
GET /api/data            ->   402 Payment Required
                              { amount: "0.01", asset: "USDC", chain: "base", payTo: "0x..." }

# 2. Client pays and retries with proof
GET /api/data
X-PAYMENT: <signed payment payload>   ->   200 OK + data

# A facilitator verifies & settles the payment on-chain.

Quickstart by framework

Add a paywall to a single route. Package APIs evolve — confirm the exact options against the official x402 docs.

Next.js

// npm install @x402/next @x402/core @x402/evm
// middleware.ts
import { paymentMiddleware } from "@x402/next";

export const middleware = paymentMiddleware(
  {
    "/api/data": {
      accepts: [{ amount: "0.01", asset: "USDC", network: "base", payTo: "0xYourAddress" }],
      description: "Premium data endpoint",
    },
  },
  { facilitator: { url: process.env.X402_FACILITATOR_URL } }
);

export const config = { matcher: ["/api/data"] };

Node.js / Express

// npm install express @x402/express @x402/core @x402/evm
import express from "express";
import { paymentMiddleware } from "@x402/express";

const app = express();

app.use(paymentMiddleware({
  "GET /weather": {
    accepts: [{ amount: "0.01", asset: "USDC", network: "base", payTo: "0xYourAddress" }],
    description: "Weather data",
  },
}));

app.get("/weather", (req, res) => res.json({ tempC: 21 }));
app.listen(3000);

Python (Flask)

# pip install x402 flask
from flask import Flask, jsonify
from x402.flask import require_payment

app = Flask(__name__)

@app.get("/data")
@require_payment(amount="0.01", asset="USDC", network="base", pay_to="0xYourAddress")
def data():
    return jsonify({"ok": True})

On the client side, libraries like @x402/fetch wrap your requests so payment + retry happen automatically. Need to settle on-chain yourself? See the facilitator list.

Live example · Sponsor

JWT Secrets — a real x402-paid API

One of the clearest live x402 services in the wild. An agent calls JWT tools — decode, verify, crack — and pays per call over HTTP 402, settling via x402 (exact scheme, USDC on Base) or MPP (Tempo / pathUSD).

decode-jwt $0.01verify-jwt $0.02crack-jwt $0.10sessions/decode-jwt $0.001/call
$ npx jwtsecrets-mcp  # run the MCP server locally
Try the machine API ↗ Pricing JSON ↗ About this sponsor →

TypeScript / JavaScript

coinbase/x402

A payments protocol for the internet. Built on HTTP.

⭐ 6.4k
GitHub →
daydreamsai/daydreams

Daydreams is a set of tools for building agents for commerce

⭐ 611
GitHub →
zachalam/x402proxy

Add x402 payment support to your API in seconds. Easily accept x402 payments and sell one-time API access—all with a single configuration and no changes to your existing codebase.

⭐ 11
GitHub →

Python

google-agentic-commerce/a2a-x402

The A2A x402 Extension brings cryptocurrency payments to the Agent-to-Agent (A2A) protocol, enabling agents to monetize their services through on-chain payments. This extension revives the spirit of HTTP 402 "Payment Required" for the decentralized agent ecosystem.

⭐ 541
GitHub →
qntx/x402-openai-python

Drop-in OpenAI Python client with transparent x402 payment support.

⭐ 260
GitHub →
Scottcjn/openclaw-x402

Drop-in x402 payment middleware for Flask APIs. Machine-to-machine payments on Base chain.

⭐ 69
GitHub →

Rust

worldliberty/agentpay-sdk

An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.

⭐ 516
GitHub →
x402-rs/x402-rs

x402 payments in Rust: verify, settle, and monitor payments over HTTP 402 flows

⭐ 280
GitHub →
qntx/r402

Rust SDK for the x402 payment protocol.

⭐ 149
GitHub →

Go

mark3labs/x402-go

Go implementation of the x402 payment protocol

⭐ 31
GitHub →
gosuda/x402-facilitator

Golang implementation of an x402 payment facilitator

⭐ 15
GitHub →

See the full ecosystem map →

Frequently asked questions

Is there an official x402 SDK?

Yes — Coinbase maintains the reference x402 implementation (coinbase/x402), which includes TypeScript middleware and packages. Most other SDKs build on the same protocol so they interoperate.

What languages have x402 SDKs?

TypeScript/JavaScript has the deepest support, followed by Python, Rust and Go. The list above covers the most-used libraries in each; the protocol is just HTTP + a signed payment, so new-language ports are straightforward.

How do I add x402 to an existing API?

Add x402 middleware in front of the routes you want to charge for. On an unpaid request it returns HTTP 402 with payment terms; once the client pays and retries with proof, the request proceeds. Libraries like coinbase/x402 (TS) and openclaw-x402 (Python/Flask) make this a few lines.

Do I need to run a facilitator to use an SDK?

No — most SDKs can point at a hosted facilitator (e.g. Coinbase’s) so you don’t settle on-chain yourself. You can also self-host one later. See the x402 facilitator list.

How do I add x402 to a Next.js app?

Install @x402/next and add paymentMiddleware in your middleware.ts, listing the routes to charge for and their price/asset/network, then restrict it with a matcher config. An unpaid request returns HTTP 402; once paid it passes through. See the Next.js quickstart above.

Is there an x402 SDK for Node and Python?

Yes. For Node, @x402/express (and adapters for Fastify and Hono) wrap your routes; for Python, packages like the x402 library add a require_payment decorator to Flask routes. Copy-paste examples for both are in the quickstart section above.