1.3 KiB
1.3 KiB
Status: done
31 — Billing ledger: per-token pricing, 90/10 split, pending balances
What to build
Tracker-side off-chain billing per ADR-0015. Each model preset gets a USDT price_per_1k_tokens in tracker config. When a request completes, the tracker debits the client's API-key ledger balance (price × total_tokens / 1000) and credits 90% to the serving nodes' pending balances proportional to work units (layers × tokens, reusing the existing ComputeAttribution), with 10% accruing to the protocol cut. API keys with insufficient balance are rejected with HTTP 402 before any routing happens — no free work.
The ledger persists in the existing tracker SQLite store and replicates across the tracker hive so any follower can serve balance reads.
This story is pure off-chain accounting — no Solana calls.
Acceptance criteria
- Per-model
price_per_1k_tokensin tracker config with sane defaults - Completed request debits client ledger:
price × total_tokens / 1000 - 90% split across serving nodes by work_units; 10% accrues to
protocol_cut - Insufficient balance → HTTP 402 before routing
- Balances survive tracker restart (SQLite) and replicate to hive followers
- Unit tests: single-node route, 3-node split, exhausted balance, restart persistence
Blocked by
23-heartbeat-stats.md25-rolling-rpm-stats.md