Overview
X-402 is an HTTP-native micropayment flow built around402 Payment Required.
With NanoGPT, X-402 lets clients pay for API calls without creating an account or pre-funding a NanoGPT balance:
- Client requests an API resource.
- Server replies
402 Payment Requiredwith payment options. - Client pays using one of the offered schemes.
- Client retries the original request with
X-PAYMENT(exact schemes), or completes the request after an on-chain transfer (polling schemes).
Supported Payment Schemes
NanoGPT can offer multiple schemes in a single 402 response:| Scheme | Network | Asset | Flow |
|---|---|---|---|
nano | nano-mainnet | XNO | Send to an ephemeral address, then poll + complete |
exact | nano:mainnet | XNO | Retry the original request with X-PAYMENT |
exact | base | USDC | Retry the original request with X-PAYMENT (EIP-3009) |
usdc-base | base | USDC | Send to an ephemeral address, then poll + complete |
Flow A: Exact Schemes (X-PAYMENT header)
- Call an API endpoint (no auth).
- Receive
402with anacceptsarray that includes anexactoption. - Construct a base64-encoded JSON payment payload and retry the same request with the
X-PAYMENTheader. - On success, the server returns the normal API response and may include
X-PAYMENT-RESPONSEwith settlement metadata.
Flow B: Polling Schemes (Ephemeral Address)
- Call an API endpoint (no auth).
- Receive
402with anacceptsentry that includespayToandpaymentId. - Send funds to
payTousing a wallet. - Poll
GET /api/x402/status/{paymentId}until the payment is ready. - Call
POST /api/x402/complete/{paymentId}to execute the original request.
API Endpoints
Get Payment Status
status values include: pending, underpaid, paid, processing, completed, failed, refunded, expired.
Complete a Payment and Execute the Original Request
X-PAYMENT header you would use when retrying the original request.
On success, the response body is the original endpoint’s response.
402 Response Format
When an endpoint returns402 Payment Required, the body includes:
- An OpenAI-compatible
errorobject x402Version- An
acceptsarray with payment options
X-Payment-Id, X-Payment-Address, and amount hints.
Pricing Notes
- Fixed-cost endpoints (for example, many media endpoints) can quote an exact USD amount in the 402 response.
- Variable-cost endpoints (for example, chat completions) may quote a maximum based on your input and the requested output limit. If the final cost is lower than the quote, the difference may be refunded automatically.