Skip to main content
Paid endpoints use the x402 protocol. A call without payment is answered with 402 Payment Required and a price; the same call with a signed Hedera payment attached is served and settled through the Blocky402 facilitator. Nothing else changes about the request.

The handshake

1

Ask

Send the request as you normally would. For POST /v1/infer that is the chat body; for GET /v1/rates/hbar nothing. Include quoteId if you hold a quote.
2

Receive the price

The seller answers 402. The PAYMENT-REQUIRED header is base64 JSON with the accepted payment options: scheme exact, the network, the asset, the amount in atomic units, the seller’s payTo account and the facilitator. The JSON body repeats the endpoint id and a hint to negotiate.
3

Pay

Build a Hedera TransferTransaction for exactly that amount to payTo, sign it with the buyer key, and encode it as the x402 payment payload. The facilitator co-signs as fee payer, so the buyer needs no HBAR for network fees beyond the price.
4

Retry

Repeat the request with the payload in the PAYMENT-SIGNATURE header. The seller verifies it with the facilitator, runs the handler, settles, and answers 200 with PAYMENT-RESPONSE carrying the transaction id.

Headers

Pin the price with a quote

The 402 price is computed from the request itself: token estimates for per-token endpoints, one unit for per-unit endpoints. To fix the amount in advance, call POST /a2a/quote first and send quoteId in the body (POST) or as a query parameter (GET). The 402 then carries the quoted amount, and the quote is marked consumed when settlement succeeds, so it cannot be replayed for a second call.

You are not charged when

  • The handler returns any 4xx or 5xx. The middleware cancels settlement, so a model outage, an unreachable mirror node or a failed audit costs nothing.
  • The payment amount does not match the challenge, or the facilitator rejects the signature. The seller answers 402 again.
  • A quote has expired or was already consumed. The 402 falls back to the list price for the request; check the amount before signing.

Two ways to do this in code

The SDK handles discovery, the quote, the payment and the retry, then verifies the settlement on the mirror node.
Budgets are enforced before anything is signed: see Spend controls.

After the call

The seller writes a receipt with the transaction id, payer, amount, the path paid for, the metering evidence and a sha256 of the response body. Read it from GET /receipts or from the receipts topic on HCS, and confirm the transfer on the mirror node as described in On-chain verification.