Skip to main content

Documentation and Tutorials

Choose the path matching your profile and follow practical guides adapted for Brazil.

Getting started by profile

Beginner

Understand and explore without coding

Learn how per request web payments work and explore live services within minutes.

  • Understand the difference between an open protocol and a cryptocurrency
  • Learn how instant unlock works without account signup
  • Browse verified services in the Brazilian directory

Practical tutorials

Beginner

Accept payments for digital content

Protect an article or PDF resource behind an HTTP 402 route and unlock delivery upon verification.

  1. Define the protected route and unit price in USDC.
  2. Attach x402 middleware returning HTTP 402 when no valid proof is attached.
  3. Test unlocking with a compatible wallet in staging.
// Conceptual route pricing configuration for digital content
const pricing = {
  price: "0.25",
  asset: "USDC",
  network: "base-sepolia",
};
Intermediate

Your first API with x402

Add per request billing to a Node or Python API in under ten minutes.

  1. Install the official x402 Foundation package in your project.
  2. Configure your recipient address and verification facilitator.
  3. Verify HTTP 402 without signature and HTTP 200 after signing.
import { paymentMiddleware } from "x402-next";

export const middleware = paymentMiddleware("0xYourRecipientAddress", {
  "/api/lookup": { price: "$0.01", network: "base-sepolia" },
});
Advanced

Integration with AI agents

Allow autonomous agents to pay for external tools and APIs with strict spend caps.

  1. Configure a per call cap and daily budget in the agent client.
  2. Intercept HTTP 402 responses automatically in the request wrapper.
  3. Store auditable settlement logs for every call made by the agent.
const response = await x402Fetch("https://api.example.com.br/data", {
  maxAmountUsdc: "0.05",
  signer: agentWalletSigner,
});

Official SDK references

Python SDK

pip install x402

Support for FastAPI, Flask, and sync or async HTTP clients.

from x402.fastapi import require_payment
app.middleware("http")(require_payment(price="0.01"))

Node SDK

npm install x402

Middleware for Express, Hono, and Next.js alongside an automated fetch client.

import { withX402 } from "x402";
const res = await withX402(fetch)("https://api.example.com.br");

Go SDK

go get github.com/x402-foundation/x402/go

Lightweight package for standard net/http servers and high concurrency services.

handler := x402.PaymentMiddleware(cfg)(myHandler)
http.ListenAndServe(":8080", handler)

Official protocol repository

Browse the full specification, open issues, reference examples, and source code directly on the x402 Foundation GitHub.

Visit github.com/x402-foundation/x402
Documentation and Tutorials | x402 Brasil