what farout is
An x402 pay-per-call LLM gateway with true-up (usage-based) billing. Your agent POSTs a chat completion, the server answers HTTP 402 with a USD spending cap, your client pays USDC on Base, retries, and gets the model response. No API key, no signup, no subscription. Settlement is on-chain and happens after the answer — charged by actual token usage, never more than the cap.
- base url:
https://farouter.tech - paid endpoint:
POST /v1/chat/completions([OI]-compatible) - anthropic alias:
POST /v1/messages - catalog + live prices:
GET /v1/models - manifest:
GET /.well-known/x402
the payment flow
- POST your request without any Authorization header.
- Read the 402. The body carries a
quote(your spending cap: USD, token estimate, per-1M prices). Thepayment-requiredresponse header carries the base64 x402 v2 requirements (schemeupto). - Build the payment with any x402 client and retry with the payment header. Official SDKs send
PAYMENT-SIGNATURE; FarOut also acceptsPAYMENTandX-PAYMENT. - On success: 200 plus a
payment-responseheader with the on-chain settlement receipt (tx hash). The settled amount is based on actual usage (true-up), not the cap.
The cap is computed from your request: estimated input tokens plus your max_tokens, at the model's per-1M price. After the model answers, settlement charges the actual usage (input + cached reads at 10% + output) — floored at $0.001, capped at $3.00. Unused budget is never taken: no refunds needed, the leftover simply isn't charged. Verify any tx on basescan.org. Failed upstream calls are cancelled automatically and never charged.
quick start
import { wrapFetchWithPayment, x402Client } from "@x402/fetch";
import { UptoEvmScheme } from "@x402/evm/upto/client";
import { toClientEvmSigner } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.BUYER_PK);
const signer = toClientEvmSigner(account);
const client = new x402Client()
.register("eip155:8453", new UptoEvmScheme(signer));
const fetchWithPay = wrapFetchWithPayment(fetch, client);
const r = await fetchWithPay(
"https://farouter.tech/v1/chat/completions",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "glm-5.3",
messages: [{ role: "user", content: "hi" }],
max_tokens: 50,
}),
});
const answer = await r.json();
Requires npm install @x402/fetch @x402/evm viem. The buyer wallet needs a little USDC on Base. Signing is gasless (Permit2); gas ETH is only needed for the one-time Permit2 approval setup. Raw machine-readable versions: /docs/agents.md and /docs/skill.md.
request fields
| field | required | notes |
|---|---|---|
model | yes | Id from GET /v1/models, e.g. glm-5.3. No provider prefix. |
messages | yes | Standard [{role, content}] array. |
max_tokens | yes | Output budget. Drives the quote directly. |
stream | no | true for SSE. Settlement happens after the stream ends. |
response codes
| code | meaning | what to do |
|---|---|---|
| 402 | quote ready | Pay and retry with the payment header. |
| 200 | paid and answered | Read the answer. Keep the payment-response receipt. |
| 400 | payment mismatch | Fetch a fresh 402 (quotes are per request) and retry. |
| 404 | unknown model | Check GET /v1/models for the current catalog. |
| 502 | upstream failed | Not charged. Retry, possibly with another model. |
cost model (true-up)
- the 402 quote is a spending cap, not the final price. You authorize the cap with one gasless Permit2 signature (x402
uptoscheme). - after the model answers, settlement charges actual usage: real input tokens + cached reads at 10% + real output tokens. Always <= the cap.
- unused budget is simply never taken — no refunds needed. Check any tx on basescan.org.
- minimum charge per successful call: $0.001. Cap: $3.00 per call (the live value is in every 402 quote).
- probe free: POST without paying to read
quote.usd(the cap) before committing. - failed calls are cancelled server-side; you are never charged for a 502.
- free gas sponsorship: prove you're a paying customer (one settled call, or
proofTx— tx hash of any USDC transfer from your wallet to the FarOut wallet) and your wallet holds exactly 0 ETH, then POST your wallet to/api/sponsor-allowanceand FarOut sends 0.000002 ETH for your one-time Permit2 approvals (upto setup). One drop per wallet.
model choice
- cheapest:
glm-5.3-flash,deepseek-v4-flash,gpt-5.6-luna - balanced:
glm-5.3,glm-5.2,kimi-k3 - flagship:
gpt-5.5,gpt-5.6-sol - live list and prices:
GET /v1/models; health:GET /api/status. Ids carry no provider prefix.
rules of thumb
- quote first when cost matters. The unpaid probe is free —
quote.usdis your worst case. - your real cost is almost always below the quote: true-up settles at actual usage.
- one payment header per request. "payment already attempted" from the SDK means rebuild the request with a fresh payload.
rate_limitedin health data is an upstream bid squeeze, not an outage. Retry or switch models.- keep
max_tokensreasonable; it sets the cap you authorize (actual usage is what gets settled, but the cap must cover it).
verification
- unpaid POST returns 402 with a
quotein the body (schemeupto). - paid POST returns 200 with model content.
- the
payment-responseheader contains a tx hash that resolves on basescan.org, and the transferred amount is <= the quoted cap (true-up billing). GET /v1/modelslists the models you use.