How to pay for a request
Start with the sandbox: it takes test USDC on Base Sepolia, which you can get free from Circle's faucet. Use a throwaway key either way.
Ask without paying
The gateway answers 402. The price, the token and the address to pay are in the PAYMENT-REQUIRED header.
curl -i "https://demo.apivend.dev/v1/balance?address=0x4C5d78BebbF28853c28eB385b936875e68107C60"Pay and ask again
An x402 client signs a USDC authorization for exactly that price and repeats the request with it. Nothing moves until the API has answered.
npm install @x402/fetch @x402/evm viem import { wrapFetchWithPaymentFromConfig } from "@x402/fetch"; import { ExactEvmScheme } from "@x402/evm"; import { privateKeyToAccount } from "viem/accounts"; const account = privateKeyToAccount(process.env.X402_PRIVATE_KEY); const pay = wrapFetchWithPaymentFromConfig(fetch, { schemes: [{ network: "eip155:84532", client: new ExactEvmScheme(account) }], // Base Sepolia only }); const res = await pay("https://demo.apivend.dev/v1/balance?address=0x4C5d78BebbF28853c28eB385b936875e68107C60"); console.log(await res.text());pip install "x402[requests,evm]" httpx # x402 needs httpx but does not install it import os from eth_account import Account from x402 import x402ClientSync from x402.http.clients import x402_requests from x402.mechanisms.evm.exact import ExactEvmScheme from x402.mechanisms.evm.signers import EthAccountSigner account = Account.from_key(os.environ["X402_PRIVATE_KEY"]) client = x402ClientSync() client.register("eip155:84532", ExactEvmScheme(signer=EthAccountSigner(account))) # Base Sepolia only print(x402_requests(client).get("https://demo.apivend.dev/v1/balance?address=0x4C5d78BebbF28853c28eB385b936875e68107C60").text)go get github.com/x402-foundation/x402/go/v2 import ( x402 "github.com/x402-foundation/x402/go/v2" x402http "github.com/x402-foundation/x402/go/v2/http" evm "github.com/x402-foundation/x402/go/v2/mechanisms/evm/exact/client" evmsigners "github.com/x402-foundation/x402/go/v2/signers/evm" ) signer, err := evmsigners.NewClientSignerFromPrivateKey(os.Getenv("X402_PRIVATE_KEY")) client := x402.Newx402Client() client.Register("eip155:84532", evm.NewExactEvmScheme(signer, nil)) // Base Sepolia only pay := x402http.WrapHTTPClientWithPayment(http.DefaultClient, x402http.Newx402HTTPClient(client)) resp, err := pay.Get("https://demo.apivend.dev/v1/balance?address=0x4C5d78BebbF28853c28eB385b936875e68107C60")go install apivend.io/apivend/cmd/x402-pay@latest X402_PRIVATE_KEY=0x… x402-pay "https://demo.apivend.dev/v1/balance?address=0x4C5d78BebbF28853c28eB385b936875e68107C60"The snippets pay on Base Sepolia only (eip155:84532), so the key next to them cannot pay real USDC by mistake. Agents with a wallet pay the same way, for example through Coinbase's Payments MCP or Cloudflare's Agents SDK.
Find your receipt
The answer comes first and the payment settles about a second later, so PAYMENT-RESPONSE has no transaction yet. Once it settles it prints on the tape with a link to the transaction, and /api/feed?payer= with your address lists your own payments.
What runs this page
This page is a reference deployment of apivend, the open-source payment gateway these APIs sit behind. The APIs themselves are ordinary HTTP services with no payment code.
- Gateway
- Envoy Gateway with apivend's x402 filter. It prices each route and checks every payment before the request reaches the API.
- Prices
- A PaymentPolicy per route, kept in Kubernetes. Changing a price takes effect in under a second.
- Cluster
- A single-node Kubernetes cluster (k3s), deployed from git by Flux.
- Settlement
- Coinbase's facilitator on Base. The sandbox uses the free x402.org facilitator.
- Chain reads
- Balances and blocks straight from Base over RPC. No payment is served on old data.