Docker is the only prerequisite for the API. The runnable Next.js example also
requires Node.js 20.9 or newer.
1. Start the stack
setup.sh waits for the API to become healthy, seeds a test account, and
creates a demo-user with five AI_CREDITS:
These are the shared dev-quickstart credentials from
scripts/create-test-account.sql. Change them before exposing the instance
to anything real.
2. Run the working integration
From the repository root, in a second terminal:
Open http://localhost:3000. Run the request five
times. Each successful call:
- checks the entitlement before doing billable work;
- runs a provider-free model stub;
- records usage, cost, and revenue;
- atomically deducts one credit.
The sixth call returns 402 from the example route before the provider stub
runs. Event ingestion remains the final enforcement boundary and returns
409 Conflict if a caller races or skips the preflight check.
Read
app/api/generate/route.ts
for the complete check → work → record flow.
3. Open the admin console
The repo also ships a web console for the operator side of the same instance.
From the repository root:
Sign in with the seeded test / password login. The console prints its URL —
http://localhost:3000, or the next free port if the
example app is still holding 3000.
You’ll see the seeded catalog (the developer_demo plan and its ai.chat
rule), the demo customer with its credit pool and transaction ledger, and every
event the example just recorded — cost and revenue on each row. The console
talks to the API through a same-origin proxy, so no CORS configuration is
needed. Details in
ui/README.md.
4. Verify the Client API
Client API calls authenticate with the API key, via either header:
Without the key, the same call returns 401. Re-run ./setup.sh to reset only
the fixed demo customer’s five credits. The billing lifecycle
guide shows how to create your own catalog and customer.
There is no signup endpoint
This is deliberate. A self-hosted billing engine’s operator is the tenant;
a public signup endpoint on your billing system would be pure attack surface.
You bootstrap your account with setup.sh (or scripts/create-test-account.sql
directly) and log in from there.