REST routes are gated by OKX's @okxweb3/app-x402-express middleware (x402 version 2, exact scheme).
The round trip#
- Call the route without paying. It answers
402with a base64PAYMENT-REQUIREDheader. - Decode it, sign an EIP-3009 authorization for the amount, and base64-encode the signed payload.
- Repeat the same request with that payload in the
PAYMENT-SIGNATUREheader. - The response carries the tool result, and
PAYMENT-RESPONSEholds the base64 settlement receipt.
curl -i "https://api.roundlot.0xo.in/v1/quote?symbol=NVDA&side=buy&size=250"
# HTTP/2 402
# payment-required: eyJ4NDAyVmVyc2lvbiI6Mi…
The header decodes to:
{
"x402Version": 2,
"error": "Payment required",
"resource": { "url": "https://api.roundlot.0xo.in/v1/quote?symbol=NVDA&side=buy&size=250", "description": "Quote an xStock trade", "mimeType": "application/json" },
"accepts": [{
"scheme": "exact",
"network": "eip155:1952",
"amount": "10000",
"asset": "0x9e29b3aada05bf2d2c827af80bd28dc0b9b4fb0c",
"payTo": "0x5BeFc3f1C3703e12edaa316599cbB4b43cB4F2a3",
"maxTimeoutSeconds": 120,
"extra": { "name": "USD₮0", "version": "1" }
}]
}
GET or POST#
Every paid route accepts GET with query parameters or POST with a JSON body. The payment covers the exact request that was quoted, so repeat it unchanged.
A malformed request gets 400 invalid_input with the problem fields, not a 402, and settlement happens only after the tool returns 2xx. A refused call is never charged.
Clients#
Any x402 v2 client that signs EIP-3009 works: OKX's fetch wrapper, the OKX CLI, or the OKX Agentic Wallet.