---
name: farout-metered-inference
description: Buy LLM inference from FarOut per call with true-up (usage-based) billing, paying USDC over x402.
---

# FarOut — Pay-Per-Call LLM Inference (True-Up Billing)

Call frontier models (GLM, GPT, Kimi K3, DeepSeek V4, MiniMax M3) from any
x402-capable agent. Pay per request in USDC on Base, charged by ACTUAL token
usage (true-up). No API key, no account.

- Endpoint: `https://farouter.tech/v1/chat/completions`
- Anthropic alias: `https://farouter.tech/v1/messages`
- Catalog with live prices: `https://farouter.tech/v1/models`
- Full integration guide: `https://farouter.tech/docs`

## When to Use

- An agent needs one-off or low-volume LLM calls and should not manage keys.
- A workflow wants metered, per-call billing with on-chain receipts where
  the charge matches real usage, not a worst-case estimate.
- Also payable from **Solana** (exact scheme via the PayAI facilitator — no
  SOL needed, PayAI covers network fees) for wallets living on Solana.
- Do not use for: high-volume streams (prepay elsewhere).

## Prerequisites

- A wallet holding USDC on Base (mainnet). Signing is gasless; the wallet
  needs gas ETH only for the one-time Permit2 approval setup.
- Node with `@x402/fetch`, `@x402/evm`, `viem` installed, or any client
  that can build x402 v2 `upto` payment payloads.

## How to Call

```js
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: "Summarize the x402 spec in 3 bullets" }],
    max_tokens: 200,
  }),
});
if (!r.ok) throw new Error(`farout: ${r.status} ${await r.text()}`);
const answer = await r.json();
// receipt with tx hash lives in the payment-response header
```

## 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, FarOut settles for the ACTUAL usage: real input
  tokens + cached reads at 10% + real output tokens. The settled amount is
  always <= the cap you authorized.
- Unused budget is simply never taken — no refunds needed. Verify any tx on
  basescan.org: the transfer is the true-up amount.
- Minimum charge per successful call: $0.001. Cap: $3.00 per call (the live
  value is in every 402 quote).
- **Gas for the one-time upto setup is FREE**: prove you're a paying customer
  — either one settled call, or `proofTx` (tx hash of any USDC transfer from
  your wallet to the FarOut wallet, e.g. your transferWithAuthorization
  settlement) — AND your wallet holds exactly 0 ETH (any ETH balance is
  rejected). Then POST `{"wallet":"0x...","proofTx":"0x..."}` to
  `/api/sponsor-allowance` and FarOut drops 0.000002 ETH for your two
  Permit2 approvals. One drop per wallet.
- Probe free: POST without paying to read `quote.usd` (the cap) first.
- Failed calls are cancelled server-side; you are never charged for a 502.
- `gpt-5.x` models require `max_completion_tokens` instead of `max_tokens`.

## Model Choice

Curated catalog of 10 frontier models. Check `GET /v1/models` for the live
list and prices; ids carry no provider prefix.

- 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`.

## Pitfalls

- Quotes are per request: a payment header from an old 402 gets a 400.
  Re-quote, then pay.
- One payment per request. "Payment already attempted" from the SDK means
  rebuild the request.
- `rate_limited` in `/api/status` is an upstream bid squeeze, not downtime.
- Keep `max_tokens` as small as the task allows; it raises the cap you
  authorize (actual usage is what gets settled, but the cap must cover it).

## Verification

- [ ] Unpaid POST returns 402 with `quote.usd` (the cap) and scheme `upto`.
- [ ] Paid POST returns 200 with `choices[0].message.content`.
- [ ] The `payment-response` header's tx hash resolves on basescan.org and
      the transferred amount is <= the quoted cap (true-up billing).
