BNB Chain developers often already hold BNB to fund gas for agents, bots, and dApp automation. This project extends that treasury pattern so the same BNB budget can also fund LLM usage through OpenRouter.
apps/api: Fastify adapter API with project creation, wallet linking, BNB deposit quoting, deposit settlement, OpenRouter proxying, usage ledgering, operator-authorized auto-top-up, and OpenAPI docs.apps/demo: Vite + React operator console with team auth, saved project sessions, wallet sync, real BSC deposit submission, auto-top-up controls, deposit history, and usage dashboards.packages/sdk: TypeScript SDK for project management, deposit flow, balance checks, and OpenAI-compatible client creation.packages/shared: Shared schemas, types, and pricing constants.contracts: Solidity deposit contract for BSC that emitsDepositReceivedevents and allows operator withdrawals.
- Deposits arrive in BNB and are converted into internal USD credits using a configurable spread and network buffer.
- Credits are reserved before an inference request is sent upstream and reconciled after the OpenRouter response returns.
- Deposits require 3 confirmations before crediting by default.
- If BNB moves more than 5% between the quote and settlement price, the deposit is marked for manual review instead of being over-credited.
- Operator auto-top-up can replenish low balances from a managed treasury budget without changing the API contract for app developers.
- Team-authenticated dashboard routes let operators manage multiple projects under one team session while project API keys remain scoped to inference and billing operations.
- A background BSC indexer watches
DepositReceivedevents, matches them to deposit intents, and credits balances automatically after the confirmation threshold. - The API can run against Prisma + Postgres in local or deployed environments, with in-memory fallback preserved for tests.
npm install
cp .env.example .env
npm run db:up
npm run prisma:generate -w @bnb-openrouter/api
npm run db:push -w @bnb-openrouter/api
npm run build
npm testTo run the API locally:
npm run dev -w @bnb-openrouter/apiTo run the demo app:
npm run dev -w @bnb-openrouter/demoThe API listens on http://localhost:3000 by default, the demo on http://localhost:5173, and the docs on http://localhost:3000/docs.
For real wallet testing in the demo:
export VITE_API_BASE_URL=http://localhost:3000
export VITE_BSC_RPC_URL=https://bsc-dataseed.binance.org
npm run dev -w @bnb-openrouter/demoPOST /v1/projectsPOST /v1/auth/registerPOST /v1/auth/loginGET /v1/auth/sessionGET /v1/dashboard/projectsPOST /v1/dashboard/projectsPOST /v1/wallets/linkPOST /v1/deposits/quotePOST /v1/deposits/intentsGET /v1/deposits/:idGET /v1/balanceGET /v1/projectGET /v1/depositsGET /v1/usagePOST /v1/auto-topup/configPOST /v1/chat/completionsPOST /v1/responsesGET /docs/openapi.json
- Prisma schema lives in schema.prisma, and local Postgres is wired through docker-compose.yml.
- The OpenAPI document is available at openapi.ts and served from
/docs/openapi.json. - The demo app is in App.tsx.
- The demo now supports team registration/login, injected-wallet connect, BSC chain switching, treasury-wallet sync, real deposit transaction submission, and automatic deposit registration after the watcher observes 3 confirmations.
POST /internal/deposits/confirmexists as a test and integration hook for chain settlement. The intended production path is the BSC watcher inapps/api/src/services/bscWatcher.ts.