How to turn your API into x402 pay-per-call (USDC on Base)
How to turn your API into x402 pay-per-call (USDC on Base)
Listing on PayAPI Market is free. AI agents pay USDC per call. PayAPI takes 0% of each job. No API keys or accounts for buyers. Here's how to make your API payable with x402 in four steps.
The x402 flow
x402 is HTTP 402 with stablecoin settlement. Your API answers an unpaid request with 402 and its price. The agent signs a payment and retries. Your server has a facilitator verify and settle it on-chain, then returns the response. On Base, settlement takes seconds.
This guide uses the x402 v2 header names. x402 v1 used X-PAYMENT and X-PAYMENT-RESPONSE, and many live APIs still accept them, so check which version your SDK speaks.
Step 1: Your API returns HTTP 402 with payment requirements
When a request arrives without payment, return HTTP 402 with a base64-encoded PAYMENT-REQUIRED header. Decoded, it lists what you accept:
{
"x402Version": 2,
"resource": { "url": "https://api.example.com/v1/your-endpoint" },
"accepts": [{
"scheme": "exact",
"network": "eip155:8453",
"amount": "2000",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"payTo": "0xYourWalletAddress",
"maxTimeoutSeconds": 60,
"extra": { "name": "USD Coin", "version": "2" }
}]
}
eip155:8453 is Base. The asset is USDC on Base, which has 6 decimals, so "2000" is $0.002. No signup flow, no API key issuer.
Step 2: The agent signs a USDC payment
The agent does not send a transaction itself. With the exact scheme on Base, it signs a USDC transfer authorization (EIP-3009) for the exact amount, to your wallet, with a short validity window and a unique nonce. The signature is the authorization.
Step 3: The agent retries with the signed payment
The agent resends the original request with a PAYMENT-SIGNATURE header holding the base64-encoded signed payment payload (X-PAYMENT in x402 v1):
GET /v1/your-endpoint HTTP/1.1
Host: api.example.com
PAYMENT-SIGNATURE: eyJ4NDAyVmVyc2lvbiI6Miwi...
Step 4: Your API verifies, settles, and returns the response
Your server sends the payload and your payment requirements to a facilitator. /verify checks the signature, amount, recipient and timing without moving funds. /settle submits the transfer on Base and waits for confirmation. You then return the data with a PAYMENT-RESPONSE header that carries the transaction hash.
// requirements = the accepts[] entry from Step 1
async function checkPayment(req, requirements) {
const header = req.headers["payment-signature"];
if (!header) return { status: 402 };
const paymentPayload = JSON.parse(Buffer.from(header, "base64").toString());
const body = JSON.stringify({ x402Version: 2, paymentPayload, paymentRequirements: requirements });
const post = (path) =>
fetch(FACILITATOR_URL + path, { method: "POST", headers: { "Content-Type": "application/json" }, body })
.then((r) => r.json());
const verified = await post("/verify");
if (!verified.isValid) return { status: 402, reason: verified.invalidReason };
const settled = await post("/settle");
if (!settled.success) return { status: 402, reason: settled.errorReason };
// settled.transaction is the on-chain transaction hash
return { status: 200, paymentResponse: Buffer.from(JSON.stringify(settled)).toString("base64") };
}
The x402 SDKs wrap this as middleware, so in practice it is a few lines of config. Don't check a transaction's native value: USDC is an ERC-20 token, so the payment shows up as a USDC Transfer event, not as ETH value. If you settle on your own instead of through a facilitator, decode that event and check the recipient and amount.
Settlement completes on Base before your API returns the response. There are no chargebacks.
A real receipt: CanonicalHash
CanonicalHash (JSON Canonicalization API) charges $0.002 per call. Route: https://canonicalhash-production.up.railway.app/v1/canonicalize. PayAPI's paid call settled on Base in transaction 0x78c4904db8263fd8ceac4d715a824ff7b9c087d69a9f8e15f7918280c6e3157a, verified 14 Oct 2026.
That transaction is the on-chain settlement receipt. The facilitator submitted the signed authorization, and the USDC contract moved 0.002 USDC (2000 units) to the provider. The transaction's native value is 0, which is why a tx.value check would never see a USDC payment.
Settlement-verified means PayAPI paid a real call from our wallet and got a real response back with an on-chain receipt. Not a health ping. A real paid transaction that settled on Base and returned usable data.
Coming soon: Solana on PayAPI Market
x402 is network agnostic and also runs on Solana. PayAPI Market verifies settlement on Base today. Solana support on PayAPI Market is coming soon, so agents will be able to pay with USDC on Solana too.
What's on PayAPI Market
PayAPI Market lists live x402 APIs, and every settlement-verified listing has been paid at least once by PayAPI's own wallet, so you know the payment flow works before you integrate. See the current listings on the marketplace.
No paid tiers. No enterprise plans. No SLAs. Listing is free and PayAPI takes 0% of each job.
Explore and list
- Browse the marketplace: payapi.market/marketplace
- Download verified routes: Export the full verified catalogue as CSV or JSON
- List your API free: payapi.market/list
FAQ
What is x402?
x402 is an open standard that uses HTTP status code 402 (Payment Required) for per-request payments. Your API returns 402 with payment requirements, the agent signs a payment and retries, and your server verifies and settles it through a facilitator before returning the response. On Base, settlement takes seconds.
Does the buyer need an API key?
No. The signed payment is the authorization. The agent makes a request, reads the price, signs a payment and retries with it in the PAYMENT-SIGNATURE header (X-PAYMENT in x402 v1). No signup, no account, no API key.
Which blockchain and token does x402 use?
x402 is network agnostic and works on EVM chains and Solana. USDC on Base is the most common setup and is what PayAPI Market verifies today. Solana support on PayAPI Market is coming soon. A facilitator submits the transaction, so the agent signs the payment but does not need ETH for gas.
What does listing cost?
Listing is free. There are no subscription tiers, no per-request fees, and no revenue share. PayAPI takes 0% of each job. PayAPI Market is a discovery marketplace, not a payment processor.
What does "settlement-verified" mean?
Settlement-verified means PayAPI paid a real call from our own wallet and received a working response with an on-chain receipt. It's not a health check or a ping. It's a real paid transaction that settled on Base and returned usable data. Every verified listing has passed this test at least once.
List your API free at payapi.market/list
Turn your existing API into a pay-per-call service without changing your core logic. Add the x402 payment check and start earning from every agent that calls your endpoint.
List your API free at payapi.market/list.