# x402 payments ## What x402 is, in five lines 1. You call the OpenAI-compatible API without any key. 2. For a paid model the gateway answers `402 Payment Required` with a quote: the price ceiling for this request, the price per 1M tokens and a task id. 3. Your wallet signs a one-time USDT authorization for that ceiling (EIP-712 typed data — no transaction, no gas on your side). 4. The request is retried with the signature in `PAYMENT-SIGNATURE`; the gateway runs it and streams the answer. 5. After the answer the gateway settles the actual amount (tokens used + the per-call fee, never above the ceiling); the `phase` object in the response carries the price, payment status and tx hash. Network: Phase L1 (chain id from the quote's `eip155:N`), asset: Bridged PHASE USDT (`USDT.e`), 6 decimals. The gateway uses the x402 `upto` scheme on the Phase chain. Generic x402 clients built for the `exact` scheme on Base and USDC cannot pay it; use the Phase SDKs or `phase-mcp`. ## Payment batches One signature per request means one on-chain settlement per request, and on cheap models that fee is most of the bill. A batch amortizes it: sign one authorization for a cap (up to \$0.10) under a gateway-issued batch id, then name the batch on your requests — `"batch"` in the body or the `X-Phase-Batch` header — with no signature at all. Each answer is charged what it costs at the batch fee (\$0.0001 per call); the gateway settles the batch with one transaction when it fills up, after five idle minutes, or when you close it. ```bash curl -s -X POST https:///v1/batches -H 'content-type: application/json' -d '{}' # 402: sign this quote (amount = the cap) # retry with PAYMENT-SIGNATURE → 201 {"id":"0x…","status":"open","cap_micro_usd":100000,"valid_before":"…"} curl -s -X POST https:///v1/chat/completions -H 'content-type: application/json' -H 'X-Phase-Batch: 0x…' \ -d '{"model":"gpt-oss-120b","messages":[{"role":"user","content":"hello"}]}' # phase.payment = "batched" curl -s -X POST https:///v1/batches/0x…/close # settle now → status "settled", tx_hash ``` A full, closed or expired batch answers 402 with `X-Phase-Batch-Error` and the quote for a new one. Nothing is locked in the wallet meanwhile: the gateway extends credit up to the cap, checks the wallet's balance before every batched request, and settles at once if it no longer covers what is owed.