Overview
NanoGPT supports accountless API calls for selected endpoints. A client can send a normal request withoutAuthorization or x-api-key, receive 402 Payment Required, pay through one of the advertised rails, then call the quoted completeUrl, replay the original endpoint with X-PAYMENT, or replay the original endpoint with Authorization: L402 <token>:<preimage> for Lightning L402.
Live demo: https://nano-gpt.com/x402
Only endpoints returned by GET /api/v1/x402/endpoints should be treated as public accountless x402 endpoints. Treat broad x402 support claims as release-gated by live smoke tests against localhost and production.
Streaming chat/responses and long-running video generation have implementation coverage but are not the stable public contract yet.
Endpoint Matrix
The supported endpoint matrix is machine-readable. Itsschemes list reflects the payment rails enabled in the current deployment.
lightning-l402 on the public endpoints listed below. Continue to use GET /api/v1/x402/endpoints as the source of truth because enabled rails can be deployment-gated.
Use ?supported=all to include beta and deferred routes:
lib/x402/publicEndpointContract.ts, which is also used by the runnable smoke test examples.
Current public accountless endpoints:
| Method | Endpoint | Stable accountless scope | Quote type | Notes |
|---|---|---|---|---|
POST | /api/v1/images/generations | JSON requests | deterministic | Image generation. |
POST | /api/v1/images/edits | JSON requests | deterministic | Multipart uploads require normal auth before conversion. |
POST | /api/v1/chat/completions | non-streaming requests | estimated with reconciliation | Set stream: false or omit streaming. |
POST | /api/v1/responses | non-streaming requests | estimated with reconciliation | Streaming and background mode are not stable accountless contract. |
POST | /api/v1/data/web/search | JSON requests | deterministic | Public v1 data path for web search. |
POST | /api/v1/data/url/scrape | JSON requests | deterministic | Public v1 data path for URL scraping. Use urls: [...]. |
Payment Schemes
Production 402 quotes currently advertise these schemes when enabled:| Public scheme | Network | Asset | Flow |
|---|---|---|---|
nano | nano-mainnet | XNO | Send XNO to a unique Nano address, then call completeUrl. |
nano-exact | Nano mainnet exact settlement | XNO | Sign an exact payment payload and replay the original request with X-PAYMENT. |
base-usdc | Base | USDC | Send USDC on Base to a unique address, then call completeUrl. |
x402-exact | Base | USDC | Use an EIP-3009 authorization in X-PAYMENT, then replay the original request. |
x402-solana-usdc | Solana/SVM | USDC | Use a Solana/SVM exact payment in X-PAYMENT, then replay the original request. |
lightning-l402 | bitcoin-lightning | sats | Pay the Lightning invoice, then replay the original request with Authorization: L402 <token>:<preimage>. |
GET /api/v1/x402/endpoints.
Working Quote Examples
All examples below intentionally omitAuthorization and x-api-key.
Text Chat
Image Generation
Web Search
URL Scrape
Flow 1: Quote, Pay, Complete
Send a normal unauthenticated request:payment object. The error object is kept for OpenAI-compatible error handling and may vary by endpoint. The legacy accepts, x402Version, and top-level requestHash fields may still appear for backwards compatibility and advanced protocol clients.
payment as the accountless payment signal; do not depend on a single legacy error.code value.
Top-level payment.statusUrl and payment.completeUrl mirror the primary advertised payment option when that option is a polling-style rail. When choosing a specific payment scheme, prefer the fields inside that option in payment.accepted[]. Exact replay options such as nano-exact, x402-exact, and x402-solana-usdc do not include statusUrl or completeUrl; successful replay settles through the X-PAYMENT response path rather than updating the original quote record. Lightning L402 options also do not use completeUrl; successful completion is the replay of the original endpoint with the Authorization: L402 <token>:<preimage> header.
After paying a nano or base-usdc quote, call:
scheme: "nano" and a unique payTo Nano address. Base USDC quote-and-complete rails use scheme: "base-usdc" and a unique Base address. For either rail, clients should copy the option-specific amountFormatted, payTo, statusUrl, and completeUrl from payment.accepted[].
Flow 2: x402 Exact Replay
Fornano-exact, x402-exact, and x402-solana-usdc, sign the advertised exact payment requirement and replay the original endpoint with:
X-PAYMENT-RESPONSE when a settlement hash is available.
For Solana USDC, select the x402-solana-usdc option from payment.accepted[] and use an x402 Solana/SVM-compatible client, such as @x402/svm, to create and sign the exact payment from the quote requirements. amount is in USDC atomic units with 6 decimals. asset is the Solana USDC mint, EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v. Copy payTo and feePayer from the quote; do not hardcode either value.
Lower-level x402 clients can also read the top-level accepts[] protocol object. For Solana USDC exact payments, it uses the official exact shape:
X-PAYMENT replay against the quoted resource, amount, and expiration. Clients should replay the same request they quoted unless endpoint docs state otherwise.
Example Solana USDC replay:
X-PAYMENT-RESPONSE header. After decoding, the shape is:
POST https://nano-gpt.com/api/v1/data/url/scrape. The request paid 1500 atomic USDC, or $0.0015, via x402-solana-usdc and returned 200 with an X-PAYMENT-RESPONSE header for network: "solana". On-chain Solana signature:
Flow 3: Lightning L402 Replay
NanoGPT also supports Lightning L402 for accountless API payments. Instead of signing anX-PAYMENT payload, the client pays a Lightning invoice and proves payment by replaying the original request with the invoice preimage.
Send the original request without Authorization or x-api-key:
lightning-l402 is enabled, the 402 Payment Required response includes a Lightning option in payment.accepted[] and a WWW-Authenticate: Payment ... challenge header. For most API clients, the easiest path is to read payment.accepted[].invoice or payment.accepted[].payTo, then read payment.accepted[].l402Token for the replay token. The challenge header is useful for clients that already implement L402 or HTTP auth challenge handling.
Example Lightning option:
WWW-Authenticate challenge includes the same token in id="<token>" and a base64-encoded request value:
request value, the JSON contains the Lightning invoice:
discountRate and undiscountedAmountUsd.
Minimal client logic:
Status Polling
For quote-and-complete rails such asnano and base-usdc, use the quoted statusUrl to watch payment state:
pendingunderpaidpaidprocessingcompletedfailedrefundedexpired
pollAfterSeconds, plus Retry-After and X-Poll-After headers.
Async media status URLs are not documented as stable accountless x402 behavior until signed unauthenticated status and media URL behavior is smoke-tested and expiration is explicitly documented.
Reconciliation
Image and data endpoint quotes are deterministic for the submitted request parameters. Chat Completions and Responses quotes are estimates and are reconciled after the provider returns usage. If provider execution fails after direct x402 settlement, the endpoint-specific failure path attempts the documented refund or failed-fee reconciliation. ForcompleteUrl, NanoGPT replays the stored original request, so the completed request is bound to the quoted method, path, and body. For exact X-PAYMENT replay, NanoGPT validates the payment against the quoted resource, amount, and expiration. For Lightning L402 replay, NanoGPT validates the token and preimage against the quoted method, path, request body hash, amount, and expiration. Clients should replay the same request they quoted unless endpoint docs state otherwise. Tool follow-up replay is separately constrained to trusted tool-call continuations.
Do not assume every accountless x402 payment is an exact final charge.
Helper Examples And Smoke Tests
Helper examples live inexamples/x402. They cover:
- quote request
- choosing a payment rail
- status polling
completeUrl- exact replay with
X-PAYMENT - Lightning L402 replay with
Authorization: L402 <token>:<preimage> - expired, underpaid, and failed completion handling via status/complete responses
Safety Notes
completeUrlpayments are bound to the original request method, path, body hash, quote amount, and expiration.- Exact
X-PAYMENTreplay is validated against the quoted resource, amount, and expiration. - Lightning L402 replay is validated against the quoted method, path, request body hash, amount, and expiration.
Authorization: L402 <token>:<preimage>is bearer payment proof. Do not log full L402 authorization headers.- Expired payments cannot be completed.
- Underpaid payments cannot be completed.
- Completed or processing payments cannot be completed twice.
- Store the original request only as long as needed for payment completion.
- Do not log
X-PAYMENTpayloads, private keys, provider credentials, or full request bodies beyond existing request logging policy.