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

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:
  1. The event is matched to a rate-card rule by provider and operation (for example openrouter/chat_completion*).
  2. 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.
  3. A per-conversation ceiling (capPerSubject) can cap the charge; a capped charge is recorded as such in the ledger entry’s pricing trace.
  4. The organization’s wallet is debited by credits_burned, and the ledger entry records the policy_version it was priced under.
Live numbers (credit value, per-rule margins, caps) are read from the active rate card, never from this page. See the credits guide for the customer-facing explanation.

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.

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