The problem: provider credits (0G iAI, monthly plan allowances) expire and can't be cashed out. The product turns that idle capacity into a market:
- Sellers verify with World ID and list credits as MTokens (1M mixed tokens at 3:1 input/output), priced below list. Their API key is checked once, then sealed with AES-256-GCM.
- Buyers — agents or people — spend them through an OpenAI-compatible router, which fills from prepaid MTokens first and otherwise takes the cheapest ask across 0G, Command Code, OpenRouter, Anthropic, OpenAI and Zen/Go. Agents with no balance get an x402 402, pay USDC on Hedera, and the retry streams.
- Traders buy or resell MTokens on an order book at /trade, or hedge tomorrow's price with 5x oracle perps on 0G Galileo at /perps, indexed from a public HCS log and liquidated by a keeper.
- Humans approve cap raises and human-linking through World ID; /receipts recomputes the index in the browser from the log.
A pnpm workspace (apps/, agents/) with four parts:
- apps/web — Next.js 16 App Router, TypeScript, no ORM magic beyond Drizzle on Neon Postgres. All domain logic lives in plain modules under apps/web/lib (ledger, book, bids, offers, rails, x402, hcs, world, approvals, payouts, perp, chain, secrets, auth), and the HTTP layer is thin route handlers under app/api/v1. The database is a double-entry-ish ledger: keys, listings, bids, offers, trades, prepaid, topups, usage, payouts, approvals, and perp_events, with balances stored as micro-USD bigint.
- Money — x402 via @x402/core + @x402/hedera: the router answers 402, the client signs an exact-scheme USDC transfer on Hedera testnet, the server settles through a facilitator and credits the key. Prepaid MTokens are spent first; the rest is settled against reported upstream usage.
- contracts — Foundry/Solidity: MockUSDC, IndexOracle (keeper-posted index), PerpMarket (5x, vault-backed, liquidations). Deployed on 0G Galileo 16602, driven from the web app with viem/wagmi and generated ABIs.
- keeper — one Node process (main.ts + jobs.ts) that publishes HCS rollups, posts the index, liquidates, matches resting bids, closes the day, schedules payouts and resets listings. It's the only index writer and a trusted component.
Request path: Bearer rk_… → SHA-256 lookup in keys → prepaid check → cheapest ask across rails → 402 or balance debit → stream from the upstream provider → usage settled → fill recorded → HCS log → index/perp feed. Seller provider keys are checked once, sealed with AES-256-GCM, and used custodied by the router. Identity is World ID (IDKit) for sellers and approvals, Privy + wagmi for wallets. Tests are node:test against real route handlers, plus live e2e scripts that spend testnet USDC.