Skip to content
NestForge

Payments

x402: the payment is the API key

x402 revives HTTP 402 Payment Required as an open standard for paying over HTTP with stablecoins. NestForge uses it for every paid action, so agents never need an account.

Currently accepted

  • Protocol: x402 v2, scheme exact
  • Asset: USDC
  • Network: Base Sepolia (eip155:84532): testnet during early access

Flow

  1. Quote. Call a paid endpoint (POST /v1/instances or /extend) without payment. You get 402 with a PaymentRequired object in the JSON body and base64-encoded in the PAYMENT-REQUIRED header.
  2. Sign. Pick accepts[0] and sign an EIP-3009 transferWithAuthorization for exactly that amount, asset and payTo. Nothing moves yet.
  3. Retry. Send the same request with PAYMENT-SIGNATURE: <base64 payload>. Legacy v1 clients may use X-PAYMENT.
  4. Settle. We verify the payload with an x402 facilitator, settle it on-chain, then create or extend the VPS.
  5. Receipt. The response carries PAYMENT-RESPONSE (base64) with the transaction hash, and the JSON includes payment.tx.
402 response body
{
  "x402Version": 2,
  "error": "payment required",
  "resource": { "url": "https://nestforge.cloud/v1/instances",
                "description": "NestForge nano x 2h", "mimeType": "application/json" },
  "accepts": [{
    "scheme": "exact",
    "network": "eip155:84532",
    "asset": "0x…",            // USDC contract
    "amount": "10000",         // atomic units: 0.01 USDC
    "payTo": "0x…",
    "maxTimeoutSeconds": 300,
    "extra": { "name": "USDC", "version": "2" }
  }]
}

Guarantees

  • Pay only on success. If verification fails you receive another 402 with the reason and nothing is charged.
  • No replays. Each payment payload can be used once; reuse returns 402 payment payload already used.
  • Exact match. Payments for a lower amount, another network, asset or recipient are rejected before settlement.

Error reasons

errorMeaning
payment requiredNo payment header was sent.
malformed payment headerHeader is not a valid base64 x402 payload.
payment does not match requirementsAmount, network, asset or payTo differs from the quote.
payment payload already usedReplay of an earlier payment.
payment invalid: …Facilitator rejected it (signature, balance, expiry …).
settlement failed: …On-chain settlement did not go through; nothing was created.

A 502 means the facilitator was unreachable, so retry with a fresh signature.