PostgreSQL-native Python and TypeScript SDKs
Open-source credits and usage billing for AI SaaS
Bursar gives AI products one exact ledger for usage pricing, prepaid credits, plans, allowances, and subscriptions.
- Python 3.12+
- Node.js 22+
- PostgreSQL 16+
- AGPL-3.0
from bursar import Bursar, PostgresStore
store = PostgresStore(
database_url,
tenant_id=tenant_id,
provider_environment="test",
)
bursar = Bursar(credit_store=store)
charge = bursar.credits.deduct(
account_id,
usage_metrics,
idempotency_key="request:0195",
)
Complete billing lifecycle
Keep pricing, access, and money state consistent
Each capability shares the same versioned configuration, tenant boundary, and transactional ledger.
Price every operation
Define metered operations, exact-decimal rates, and plan-specific pricing in one validated configuration.
Read the guideControl spend before work starts
Enforce allowances, quotas, entitlements, and concurrency limits in the same transaction as admission.
Read the guideMaintain an auditable ledger
Record grants, purchases, charges, refunds, and expiry as immutable entries with replay-safe mutations.
Read the guideConnect payments when needed
Map provider events to subscriptions, top-ups, plan changes, and guarded auto-recharge workflows.
Read the guideOne system of record
Put the financial boundary behind one facade
Bursar prices usage, checks policy, and commits the result in one transaction. Payment integrations remain optional.
Explore the architectureBehavioral parity
Use the same model from Python and TypeScript
Both SDKs share the configuration schema, expression fixtures, PostgreSQL migrations, rounding rules, and error contract.
python -m pip install "bursar[postgres]"from bursar import Bursar, PostgresStore
store = PostgresStore(
database_url,
tenant_id=tenant_id,
provider_environment="test",
)
bursar = Bursar(credit_store=store)
charge = bursar.credits.deduct(
account_id,
usage_metrics,
idempotency_key="request:0195",
)
npm install @zonastery/bursar pgimport { Bursar, PostgresStore } from "@zonastery/bursar";
const store = new PostgresStore({
postgres: process.env.DATABASE_URL!,
tenantId,
providerEnvironment: "test",
});
const bursar = new Bursar({ creditStore: store });
const charge = await bursar.credits.deduct(accountId, usageMetrics, {
idempotencyKey: "request:0195",
});
Start with an isolated ledger
Build the first metered charge
Install the schema, publish a config, create an account, and inspect the resulting ledger entry.