Credits contract and each reply is paid from them, on chain. The contract is deployed on Base Sepolia (0xF0FC5a7a6801C6eBDBC23793a32B0fF5dd9e89dc), and replies have been charged on it (receipts on Contracts); this page describes how it works (apps/be/src/credits.ts).
How the price is worked out
- The engine measures each run: input, output and cached tokens, times the model’s live price per token from NEAR AI Cloud’s model list. That is the provider cost (
costUsd). - The backend adds the markup (
CREDIT_MARKUP_PERCENT, 10 by default) and rounds up to a micro-dollar, at least one. - The reply’s charge is recorded and counted against the owner’s credits at once (pending), so the next run already sees it.
- Settled in batches. One
Credits.chargecosts about 141k gas, which can be more than a short reply is billed. So the backend’s biller key sends oneCredits.charge(owner, amount, ref)per account for many replies: when that account’s pending charges reach $0.05 (`SETTLE_MIN_CREDITS`) or the oldest is an hour old (`SETTLE_MAX_AGE_MINUTES`), at most $2 in one. Therefis fixed for that batch before the first try and the contract refuses arefit has seen, so a retry can never charge twice. A failed settlement is retried every minute, up to five times. Each reply in the history then links to its batch’s transaction.
hellopie. A live charge on the current setup has not been run yet.
Limits that protect the owner
Before a run, the backend checks on chain that the owner’s balance, minus charges not sent yet, covers at least $0.002 (
MIN_RUN_CREDITS) and that the daily cap has that much room; otherwise the API answers 402 insufficient_credits or 402 daily_cap_reached and nothing runs.
Topping up
- From the owner’s wallet: the Credits screen asks the wallet to
approveanddepositUSDC, then sends the transaction hash toPOST /v1/credits/topups. The backend records it only from the receipt: a successful transaction whoseDepositedevent credits the signed-in address. - From the Mind’s wallet: ask the Mind (skill
credits, tooltopup_credits). It waits for the owner’s approval, then sendsapproveplusCredits.depositfrom the Mind’s governed account (both are whitelisted for its role), within the daily cap the backend enforces.
API
GET /v1/credits (balance, pending charges, daily cap and what is left today, read on chain), GET /v1/credits/history (top-ups and charges with their transactions), POST /v1/credits/topups. See the API reference.
Guests run on the team’s credit and see no balance.