All tools

x402 tool

402 Header Generator

Build a valid HTTP 402 Payment Required challenge, or encode an X-PAYMENT request header. Amounts convert to atomic units automatically. Runs in your browser.

402 response body
{
  "x402Version": 1,
  "error": "X-PAYMENT header is required",
  "accepts": [
    {
      "scheme": "exact",
      "network": "base",
      "maxAmountRequired": "10000",
      "resource": "https://api.example.com/v1/report",
      "description": "Premium market report",
      "mimeType": "application/json",
      "payTo": "0x2Ff1a3c9F8b5A1D0e7C4b6a2E9d8F7c6B5a4D3e2",
      "maxTimeoutSeconds": 60,
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
    }
  ]
}
Raw HTTP response
HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "x402Version": 1,
  "error": "X-PAYMENT header is required",
  "accepts": [
    {
      "scheme": "exact",
      "network": "base",
      "maxAmountRequired": "10000",
      "resource": "https://api.example.com/v1/report",
      "description": "Premium market report",
      "mimeType": "application/json",
      "payTo": "0x2Ff1a3c9F8b5A1D0e7C4b6a2E9d8F7c6B5a4D3e2",
      "maxTimeoutSeconds": 60,
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
    }
  ]
}
Express
app.get("/v1/report", (req, res) => {
  if (!req.headers["x-payment"]) {
    return res.status(402).json({
      "x402Version": 1,
      "error": "X-PAYMENT header is required",
      "accepts": [
        {
          "scheme": "exact",
          "network": "base",
          "maxAmountRequired": "10000",
          "resource": "https://api.example.com/v1/report",
          "description": "Premium market report",
          "mimeType": "application/json",
          "payTo": "0x2Ff1a3c9F8b5A1D0e7C4b6a2E9d8F7c6B5a4D3e2",
          "maxTimeoutSeconds": 60,
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
        }
      ]
    });
  }
  // …verify the X-PAYMENT header, then serve the resource
});

Generating x402 headers

x402 turns the reserved HTTP 402 Payment Required status code into a working paywall for APIs and AI agents. There are two payloads in the exchange, and this tool builds both:

  • The 402 challenge is what your server returns to an unpaid request — a JSON body with an accepts[] array of payment options. The generator converts your USDC amount to the atomic maxAmountRequired integer and hands you the JSON, a raw HTTP response, and a drop-in Express handler.
  • The X-PAYMENT header is what a client sends on the paid retry — base64-encoded JSON with the scheme, network, and payment payload. Handy for mocking a paid request in tests.

Need to read these payloads instead of write them? Use the 402 Payload Parser. To see every payment your agents make across all your APIs, try 402.report.

Frequently asked questions

What does a 402 Payment Required response look like?
An x402 server returns HTTP 402 with a JSON body of the shape { x402Version, accepts: [ … ] }. Each entry in accepts[] describes one way to pay: scheme, network, maxAmountRequired (an atomic integer amount), asset, payTo, resource, and an optional description and maxTimeoutSeconds. This generator builds that body for you and converts your human-readable amount to atomic units.
What is the X-PAYMENT header?
It is the header the client sends when it retries a request after paying. The value is base64-encoded JSON containing the scheme, network, and a payment payload. The generator's second mode encodes that header from the fields you supply — useful for mocking a paid request in tests.
Does this sign or send a real payment?
No. 402.report is non-custodial and never signs, holds, or broadcasts transactions. This tool only formats and base64-encodes the data you enter, for local development and testing. Use your own wallet or facilitator to produce real signatures.
How are amounts converted?
USDC uses 6 decimal places, so the tool multiplies your major-unit amount by 1,000,000 to produce the atomic maxAmountRequired string (e.g. 0.01 USDC becomes "10000"). Rounding is done in integer space to avoid floating-point drift.