x402
The HTTP payment protocol that lets a program pay for one generation in USDC from its own wallet, with no account.
x402 puts a price on an HTTP request. The server answers an unpaid request with 402 and what to pay; the client pays in its retry and gets the result. Shader's four generation endpoints speak x402 version 2 with the exact scheme in USDC on Solana.
- Requestno account
- 402PAYMENT-REQUIRED
- SignUSDC transfer, exact
- RetryPAYMENT-SIGNATURE
- 200PAYMENT-RESPONSE
#The three headers
| Header | Sent by | Holds, as base64 JSON |
|---|---|---|
PAYMENT-REQUIRED | The server, on the 402 | What to pay: scheme, network, amount in atoms, the USDC mint, payTo, and in extra the feePayer |
PAYMENT-SIGNATURE | The client, on the retry | The requirement it accepted and payload.transaction, its signed payment |
PAYMENT-RESPONSE | The server, on the 200 | success, the settlement transaction signature, the network and the payer |
#The payment
The payment is a v0 transaction with Shader's sponsor as fee payer: a compute-unit limit, a compute-unit price of 0, and one transferChecked of exactly the amount to the treasury. The client signs it as the token owner only; the server checks it, co-signs as fee payer and lands it before it generates. The paying wallet needs USDC and no SOL.
The amount is the generation's price in USDC atoms, one atom per credit base unit, so an image at 40 credits costs 40,000 atoms, $0.04. A paid job does not touch any credit account.
A payment is used once: the same PAYMENT-SIGNATURE sent again answers PAYMENT_INVALID. It shows in receipts as kind x402 under the payer's wallet. If a paid generation fails, the job says so with refundRequired: true, and the payment is held for a refund by the operator.
#Renting a GPU
A rental's price depends on how long it runs, so rentals use the upto scheme instead of exact. POST /x402/rent/{gpuId} answers 402 with a quote for one machine at its live price, and a ceiling: that rate times the most seconds the rental may run. The agent signs an open of a payment channel that escrows the ceiling and names the quote in a memo; Shader co-signs it as fee payer and launches the machine at the locked rate.
The channel closes when the rental stops: by its stop token, by the payer's own Stop, or by itself when it reaches the ceiling. Shader stops the machine first, then charges the seconds run at the locked rate, never more than the ceiling. A voucher signed for that amount seals the channel, and distribute pays the charge to payTo and the rest of the deposit back to the agent's wallet. A channel that reaches its expiry with no voucher refunds in full.
One rental can run through several channels. Extending it with its stop token opens a further channel at the same locked rate, paid from the same wallet; when a channel's ceiling is used up it closes for that ceiling and the seconds carry on against the next. Each channel closes with its own receipt, and an extension never used is refunded in full.
Pay over x402 runs a generation payment end to end and decodes the rental 402 field by field.