Overview
NanoGPT supports accountless API calls for selected endpoints. To request an accountless x402 quote, send the API request withoutAuthorization or x-api-key, and include x-x402: true. NanoGPT will return 402 Payment Required with available payment options. After paying, call the quoted completeUrl, replay the original endpoint with X-PAYMENT, or replay the original endpoint with Authorization: L402 <token>:<preimage> for Lightning L402.
An unauthenticated API request without x-x402: true is treated as a normal unauthenticated request and returns 401 missing_api_key. NanoGPT does not generate x402 quotes for every unauthenticated request.
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:
Only endpoints that return a valid 402 quote in smoke tests should be listed as supported. Do not assume other API endpoints support accountless payment until they appear as supported in the matrix and have passed live smoke tests.
Payment Schemes
Production 402 quotes currently advertise these schemes when enabled:
Solana USDT and native SOL are not documented x402 exact rails. Do not list either as a supported accountless x402 scheme until it appears in
GET /api/v1/x402/endpoints.
Working Quote Examples
All initial quote examples below intentionally omitAuthorization and x-api-key and include x-x402: true.
Text Chat
Image Generation
Web Search
URL Scrape
Flow 1: Quote, Pay, Complete
To request an accountless x402 quote, send the API request withoutAuthorization or x-api-key, and include x-x402: true. NanoGPT will return 402 Payment Required with available payment options.
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.
To request an accountless Lightning L402 quote, send the original request without Authorization or x-api-key, and include x-x402: true:
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.
Troubleshooting
If you receive401 missing_api_key immediately, check that the initial quote request includes x-x402: true. Without that header, NanoGPT does not enter the x402 quote flow.
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.