Skip to main content

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.
This endpoint incurs provider cost and records a billing event via record_external_cost_event(). Credits are deducted from the organization’s wallet based on the configured margin multiplier.

Pricing Model

For each billable operation:
  1. charged_usd = raw_cost_usd * margin_multiplier
  2. credits_burned = charged_usd / credit_value_usd
  3. Organization wallet is debited by credits_burned
Example: A chat completion with raw cost of 0.01resultsin0.01 results in 0.02 charged, burning 0.04 credits.

Platform Billing Summary (Superadmin)

Get platform-wide billing summary with cost vs. revenue analysis.
This endpoint requires superadmin access. Non-superadmin requests receive 403 Forbidden.

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 the record_external_cost_event() PostgreSQL function, which performs the entire flow in a single transaction:
  1. Load billing defaults
  2. Ensure org billing account exists
  3. Lock wallet row
  4. Calculate charged USD and credits burned
  5. Update wallet balance
  6. Insert cost event record
  7. Insert ledger entry
  8. Return billing result
This ensures wallet balances are always consistent under concurrent load.

List Public Billing Plans

Returns the active billing plan catalog shown on the signup page. No authentication required.

Response (200)

boolean
object[]
Array of active plans.

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