Skip to main content

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
One workflow, two SDKsCurrent stable
Python
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",
)

One 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 architecture

Behavioral parity

Use the same model from Python and TypeScript

Both SDKs share the configuration schema, expression fixtures, PostgreSQL migrations, rounding rules, and error contract.

Pythonpython -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",
)
Browse the Python API
TypeScriptnpm install @zonastery/bursar pg
import { 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",
});
Browse the TypeScript API

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.