Docs · x402
Pay per request with x402
No account and no key. Your agent asks, gets a price in USDC, pays it from its own wallet and gets the result.
How a request is paid
-
Request
Your agent calls a tool’s x402 endpoint with no payment attached.
-
Quote
Strale answers
402 Payment Requiredwith the price in USDC on Base, the payee address and how long the quote stays valid. -
Pay
The agent’s wallet signs a USDC authorisation for that amount. Signing costs the buyer no gas, so the wallet needs USDC and no ETH.
-
Repeat
The agent sends the same request again with the signed payment in the
PAYMENT-SIGNATUREheader. Strale runs the tool, settles the payment once the tool returns a usable result, and answers with the result. A failed call is not charged.
See a price quote
Asking for a quote costs nothing and needs no wallet. This asks for Address Geocoding, the lowest-priced eligible tool in the catalogue at $0.0216 USDC a call.
curl -i 'https://api.strale.io/x402/v2/address-geocode?address=Eiffel+Tower%2C+Paris' The response is HTTP 402. The quote is in the body, and also in the PAYMENT-REQUIRED header on /x402/v2/ paths. Trimmed:
{
"x402Version": 2,
"error": "Payment required. Address Geocoding costs $0.0216 USDC per call.",
"accepts": [
{
"scheme": "exact",
"network": "eip155:8453",
"amount": "21600",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"payTo": "<Strale’s payee address>",
"maxTimeoutSeconds": 300,
"extra": {
"name": "USD Coin",
"version": "2"
}
}
]
} amount is in USDC atomic units, six decimals: 21600 is $0.0216. The quote is valid for 300 seconds.
Make a paid call
-
Fund a wallet
Use a wallet on Base that holds a little USDC. The tool above costs $0.0216 a call. Export its private key as
X402_PRIVATE_KEYfor this script, and use a dedicated wallet for it. -
Install the x402 client
Installnpm install @x402/core @x402/evm viem -
Run the script
It requests the tool, reads the quote, signs a payment for that amount and repeats the request.
buy.tsimport { x402Client, x402HTTPClient } from "@x402/core/client"; import { ExactEvmScheme } from "@x402/evm"; import { privateKeyToAccount } from "viem/accounts"; const account = privateKeyToAccount(process.env.X402_PRIVATE_KEY as `0x${string}`); const client = x402Client.fromConfig({ schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }], }); const http = new x402HTTPClient(client); const url = "https://api.strale.io/x402/v2/address-geocode?address=Eiffel+Tower%2C+Paris"; const first = await fetch(url); if (first.status !== 402) { console.log(first.status, await first.json()); process.exit(0); } // The 402 body is the price quote. Sign a payment for exactly that amount. const quote = await first.json(); const payload = await client.createPaymentPayload(quote); const paid = await fetch(url, { headers: http.encodePaymentSignatureHeader(payload) }); console.log(paid.status, JSON.stringify(await paid.json(), null, 2)); console.log(paid.headers.get("X-PAYMENT-RESPONSE")); // base64 JSON with the settlement transactionRun it with
X402_PRIVATE_KEY=0x… npx tsx buy.ts. A runnable version is in the repository atexamples/x402-autonomous-buyer. -
Read the result
A paid call returns HTTP 200 with the tool’s output as the body. The extra
_metafield carries the capability, the latency, the provenance and the payment, including the settlement ID. TheX-PAYMENT-RESPONSEheader holds the settlement transaction as base64 JSON.
Eligible tools
275 tools and 89 bundled checks accept x402 today. The set changes, so read it from the catalogue instead of assuming a tool is on it. Tools that are not on it run with an API key through the REST API or MCP.
| What | Where |
|---|---|
| Catalogue with prices, inputs and endpoints | https://api.strale.io/x402/catalog |
| Machine-readable discovery | https://api.strale.io/.well-known/x402.json |
| A tool | https://api.strale.io/x402/v2/{slug}. Tools with simple inputs take GET with the inputs in the query string. The catalogue gives each tool’s method; use POST with a JSON body when it says so. |
| A bundled check | POST https://api.strale.io/x402/solutions/{slug} with a JSON body of inputs. |
| On the website | Tools that accept x402 |
Both /x402/{slug} and /x402/v2/{slug} work. The v2 path always sends the current quote format with CAIP-2 network names; the older path serves older clients. Use v2 for new code. Free tools need no payment at all: call them with the REST API without a key.
Responses and errors
| HTTP | Meaning | What to do |
|---|---|---|
| 200 | Paid and done. The body is the tool’s output plus _meta. | Use the output. |
| 402 | No payment, or the payment did not verify. The body is a fresh quote, and error says why a payment failed, for example an empty wallet. | Sign the quote in the body and repeat the request. |
| 400 | The inputs are wrong. The body has error_code (invalid_request or execution_failed), charged: false, the tool’s input_schema and an example. | Fix the inputs. On execution_failed the inputs may be fine and the source failed: retry with backoff. |
| 404 | No such tool, or it is not on x402. | Check the catalogue. |
| 503 | The tool was switched off for x402, or x402 is not available right now. No payment was taken. | Retry later, or use an API key. |
- There are no transaction IDs on this route. Keep
_meta.payment.settlement_idas your record of a call. - Each call stands alone. There is no balance, no spend cap and no
max_price_cents; the quote is the price you agree to by signing it.