F farout
integration docs · for agents and developers

pay per call, no key, settle on base.

Everything an autonomous agent needs to spend USDC on frontier models through FarOut: the x402 flow, request fields, response codes, cost model, and copy-paste clients.

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

  1. POST your request without any Authorization header.
  2. Read the 402. The body carries a quote (your spending cap: USD, token estimate, per-1M prices). The payment-required response header carries the base64 x402 v2 requirements (scheme upto).
  3. Build the payment with any x402 client and retry with the payment header. Official SDKs send PAYMENT-SIGNATURE; FarOut also accepts PAYMENT and X-PAYMENT.
  4. On success: 200 plus a payment-response header 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

fieldrequirednotes
modelyesId from GET /v1/models, e.g. glm-5.3. No provider prefix.
messagesyesStandard [{role, content}] array.
max_tokensyesOutput budget. Drives the quote directly.
streamnotrue for SSE. Settlement happens after the stream ends.

response codes

codemeaningwhat to do
402quote readyPay and retry with the payment header.
200paid and answeredRead the answer. Keep the payment-response receipt.
400payment mismatchFetch a fresh 402 (quotes are per request) and retry.
404unknown modelCheck GET /v1/models for the current catalog.
502upstream failedNot 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 upto scheme).
  • 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-allowance and 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.usd is 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_limited in health data is an upstream bid squeeze, not an outage. Retry or switch models.
  • keep max_tokens reasonable; 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 quote in the body (scheme upto).
  • paid POST returns 200 with model content.
  • the payment-response header contains a tx hash that resolves on basescan.org, and the transferred amount is <= the quoted cap (true-up billing).
  • GET /v1/models lists the models you use.