Billing
Brainstormer uses a credit-based billing system. All external provider costs (AI completions, embeddings, vector operations, voice, storage) are converted to credits and deducted from the organization’s wallet.All API requests require a valid JWT token in the
Authorization: Bearer <token> header. The API Gateway decodes the JWT and forwards auth context (user-id, organization-id, user-email, x-platform-role, x-org-role) as headers to downstream services.Pricing Model
Each billable operation is priced under the active rate policy (a versioned rate card managed by superadmins under Platform Billing → Rate Card), not a single global multiplier:- The event is matched to a rate-card rule by provider and operation (for example
openrouter/chat_completion*). - The rule’s margin is applied to the provider’s raw cost, and the result is converted to credits at the policy’s fixed credit value.
- A per-conversation ceiling (
capPerSubject) can cap the charge; a capped charge is recorded as such in the ledger entry’s pricing trace. - The organization’s wallet is debited by
credits_burned, and the ledger entry records thepolicy_versionit was priced under.
Platform Billing Summary (Superadmin)
Get platform-wide billing summary with cost vs. revenue analysis.Query Parameters
string
Start of reporting period (ISO 8601 datetime). Optional.
string
End of reporting period (ISO 8601 datetime). Optional.
string
Filter to a specific organization UUID. Optional.
Response (200)
object
Aggregate totals for the period.
object[]
Day-by-day breakdown for charting.
object[]
Breakdown by provider (OpenRouter, Pinecone, ElevenLabs, etc.).
object[]
Breakdown by organization.
object[]
Distribution of organizations across billing plans.
Billable Operations
The following operations are currently billed:Data Model
Core Tables
Atomic Billing Function
All billing writes happen through therecord_external_cost_event() PostgreSQL function, which performs the entire flow in a single transaction:
- Load billing defaults
- Ensure org billing account exists
- Lock wallet row
- Calculate charged USD and credits burned
- Update wallet balance
- Insert cost event record
- Insert ledger entry
- Return billing result
Get Organization Billing Account
Returns the caller’s organization billing account: plan terms, credit balances, resource usage/limits, and when plan credits next reset. Requires authentication.Response (200)
object
billingCycleEnd was removed from this response — it was a stored column with
no writer (dead schema; see docs/architecture/CREDIT_BALANCE_MODEL.md). Use
nextResetAt / resetKind for the renewal date.List Admin Billing Plans
Returns all billing plans for superadmin management. Requires superadmin access.Response (200)
object[]
Array of all plans.
Update a Billing Plan
Updates a billing plan. Requires superadmin access. The plan name is read-only.Body
number
Monthly credit allocation.
number
Monthly price in USD.
number | null
Maximum agents allowed. Pass
null for unlimited.number | null
Maximum knowledge bases allowed. Pass
null for unlimited.string
Plan description shown on signup cards.
Response (200)
boolean

