### Setup Python Development Environment Source: https://github.com/zonastery/bursar/blob/main/CONTRIBUTING.md Commands to clone the repository and install dependencies using uv. ```bash git clone https://github.com/Zonastery/bursar.git cd bursar/python uv sync # runtime deps uv sync --extra test # ruff, pyright, pytest, testcontainers # or, for the full dev group (notebooks, psycopg2, etc.): uv sync --group dev ``` -------------------------------- ### Setup JavaScript Development Environment Source: https://github.com/zonastery/bursar/blob/main/CONTRIBUTING.md Command to install dependencies for the JavaScript SDK using Bun. ```bash cd bursar/javascript bun ci # Bun 1.3.14; installs the committed bun.lock ``` -------------------------------- ### Install project dependencies Source: https://github.com/zonastery/bursar/blob/main/docs/README.md Initializes the development environment by installing Python and Node.js dependencies across the repository directories. ```bash cd python uv sync --group dev uv pip install --python .venv sphinx sphinx-markdown-builder source .venv/bin/activate cd ../javascript bun ci cd ../docs npm ci ``` -------------------------------- ### Install Python package and run migrations Source: https://github.com/zonastery/bursar/blob/main/docs/docs/quickstart.mdx Installs the Bursar Python package with PostgreSQL support and initializes the database schema. ```bash python -m pip install "bursar[postgres]" export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/bursar" bursar migrate ``` -------------------------------- ### Install and Migrate Bursar Source: https://github.com/zonastery/bursar/blob/main/README.md Install the package and apply the database migrations using the CLI. ```bash pip install bursar[postgres] export DATABASE_URL=postgresql://... bursar migrate ``` -------------------------------- ### Run Database Migrations Source: https://github.com/zonastery/bursar/blob/main/docs/docs/javascript-api/index.mdx Install the Python CLI and execute migrations using the DATABASE_URL environment variable. ```bash pip install "bursar[postgres]" DATABASE_URL=postgres://... bursar migrate ``` -------------------------------- ### Start Docusaurus development server Source: https://github.com/zonastery/bursar/blob/main/docs/README.md Launches the local development server, which automatically triggers the prestart hook to regenerate API and notebook artifacts. ```bash npm start ``` -------------------------------- ### Run Python Integration Tests with Docker Source: https://github.com/zonastery/bursar/blob/main/CONTRIBUTING.md Commands to start a PostgreSQL container and run tests against it. ```bash docker run -d --name bursar-pg -e POSTGRES_PASSWORD=postgres \ -e POSTGRES_DB=bursar -p 5432:5432 \ public.ecr.aws/supabase/postgres:17.6.1.156 DATABASE_URL=postgresql://postgres:postgres@localhost:5432/bursar uv run pytest ``` -------------------------------- ### Install Bursar Google ADK plugin Source: https://github.com/zonastery/bursar/blob/main/docs/docs/guides/google-adk.mdx Install the Bursar package with the required Google ADK and Postgres extras. ```bash pip install "bursar[google-adk,postgres]" ``` -------------------------------- ### Initialize credit lifecycle environment Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/04_credit_lifecycle.ipynb Sets up a temporary PostgreSQL store, publishes pricing configuration, and initializes a user account with a pro plan. ```python from decimal import Decimal from bursar.metrics import UsageMetrics from shared import cleanup, base_config, publish_config, start_postgres_store, USER_ADA def completion(output=Decimal(500)): return UsageMetrics( operation="completion", measures={ "input_tokens": Decimal(1000), "output_tokens": output, "cache_read_tokens": Decimal(200), }, dimensions={"model": "gpt-4o"}, ) def execution(jobs=Decimal(1)): return UsageMetrics( operation="execution", measures={"jobs": jobs, "compute_seconds": Decimal(30)}, dimensions={"model": "gpt-4o"}, ) store, pgdata = start_postgres_store() bursar = publish_config(store, base_config()) bursar.accounts.on_account_created(USER_ADA, "signup") bursar.credits.set_user_plan(USER_ADA, "pro") print("temporary postgres:", pgdata) ``` -------------------------------- ### Bootstrap a tenant with configuration Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/13_cli_and_deployment.ipynb Provisions a tenant and applies an initial configuration in one step. The configuration file is validated before the tenant is created. ```bash bursar tenant bootstrap promo pricing.prod.yaml --label "initial: standard rate card" # -> Tenant 3f6a2b7e-8c1d-4e9a-9f2b-7c0d5e1a3b4c bootstrapped successfully (config applied). ``` -------------------------------- ### Install Bursar with Postgres support Source: https://github.com/zonastery/bursar/blob/main/docs/docs/python-api/index.mdx Install the package with the required Postgres backend dependencies. ```bash pip install "bursar[postgres]" ``` -------------------------------- ### Install Bursar SDK Source: https://github.com/zonastery/bursar/blob/main/docs/docs/javascript-api/index.mdx Install the package via npm. Requires Node.js 22 or newer. ```bash npm install @zonastery/bursar ``` -------------------------------- ### Initialize Bursar environment and create account Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/05_plans_and_allowances.ipynb Sets up a temporary Postgres store and initializes the Bursar configuration, creating a user account on the default free plan. ```python from decimal import Decimal from bursar.metrics import UsageMetrics from shared import cleanup, base_config, publish_config, start_postgres_store, USER_ADA def completion(output=Decimal(500)): return UsageMetrics( operation="completion", measures={ "input_tokens": Decimal(1000), "output_tokens": output, "cache_read_tokens": Decimal(200), }, dimensions={"model": "gpt-4o"}, ) def execution(jobs=Decimal(1)): return UsageMetrics( operation="execution", measures={"jobs": jobs, "compute_seconds": Decimal(30)}, dimensions={"model": "gpt-4o"}, ) store, pgdata = start_postgres_store() bursar = publish_config(store, base_config()) bursar.accounts.on_account_created(USER_ADA, "signup") print("created on plan:", bursar.credits.get_user_plan(USER_ADA).plan_key) ``` -------------------------------- ### PricingEngine.fromDict Source: https://github.com/zonastery/bursar/blob/main/docs/docs/javascript-api/pricing-engine.mdx Initializes a new PricingEngine instance from a canonical configuration dictionary. ```APIDOC ## PricingEngine.fromDict ### Description Creates a new PricingEngine instance. Validates the configuration document and throws ConfigError if invalid fields or references are detected. ### Signature `PricingEngine.fromDict(configDict: object): PricingEngine` ### Parameters - **configDict** (object) - Required - A canonical configuration document. ``` -------------------------------- ### Create a tenant Source: https://github.com/zonastery/bursar/blob/main/docs/docs/quickstart.mdx Initializes a new tenant and sets the environment variable for the tenant ID. ```bash bursar tenant create acme --display-name "Acme" export BURSAR_TENANT_ID="018f7f5f-7b4a-7000-8000-000000000001" ``` -------------------------------- ### PricingEngine.from_dict Source: https://github.com/zonastery/bursar/blob/main/docs/docs/python-api/pricing-engine.mdx Initializes a new PricingEngine instance from a canonical configuration dictionary. ```APIDOC ## PricingEngine.from_dict(config_dict) ### Description Creates a new PricingEngine instance. Validates the configuration document and raises ConfigError if invalid fields, measures, or dimensions are detected. ### Parameters - **config_dict** (dict) - Required - A canonical configuration document. ### Example ```python from bursar import PricingEngine engine = PricingEngine.from_dict(config_dict) ``` ``` -------------------------------- ### Build the PricingEngine from a configuration Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/02_pricing_engine.ipynb Constructs a stateless PricingEngine instance using a validated configuration dictionary. ```python from decimal import Decimal from bursar.engine import PricingEngine from bursar.metrics import UsageMetrics from shared import base_config engine = PricingEngine.from_dict(base_config()) print("engine built from canonical config") ``` -------------------------------- ### Install and Update Bursar Skill Source: https://github.com/zonastery/bursar/blob/main/skills/README.md Commands to manage the Bursar skill installation at project or global levels, and to update existing project-scoped skills. ```bash npx skills add zonastery/bursar@bursar ``` ```bash npx skills add zonastery/bursar@bursar --global ``` ```bash npx skills update --project ``` -------------------------------- ### Percentile Function Usage Source: https://github.com/zonastery/bursar/blob/main/docs/docs/concepts/expressions.mdx Examples of calculating percentiles using linear interpolation. ```text percentile(50, input_tokens, output_tokens, tool_calls) # median of 3 values percentile(0, a, b, c) # min percentile(100, a, b, c) # max ``` -------------------------------- ### Bootstrap tenant pricing Source: https://github.com/zonastery/bursar/blob/main/docs/docs/guides/multitenancy.mdx Provision a tenant while simultaneously publishing initial pricing from a configuration file. ```bash export BURSAR_TENANT_ID=018f7f5f-7b4a-7000-8000-000000000001 bursar tenant bootstrap acme ./pricing.yaml \ --display-name "Acme" ``` -------------------------------- ### Update project-scoped skills Source: https://github.com/zonastery/bursar/blob/main/docs/docs/agent-skills.mdx Update skills installed at the project level after a new Bursar release. ```bash npx skills update --project ``` -------------------------------- ### Initialize Bursar sandbox environment Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/06_quotas_and_spend_caps.ipynb Sets up a temporary Postgres store and configures a user with a pro plan and initial credits. ```python from decimal import Decimal from bursar.metrics import UsageMetrics from shared import cleanup, base_config, publish_config, start_postgres_store, USER_ADA def completion(output=Decimal(500)): return UsageMetrics( operation="completion", measures={ "input_tokens": Decimal(1000), "output_tokens": output, "cache_read_tokens": Decimal(200), }, dimensions={"model": "gpt-4o"}, ) store, pgdata = start_postgres_store() bursar = publish_config(store, base_config()) bursar.accounts.on_account_created(USER_ADA, "signup") bursar.credits.set_user_plan(USER_ADA, "pro") bursar.credits.add_credits(USER_ADA, Decimal("200.00"), entry_type="purchase", idempotency_key="topup") print("ready") ``` -------------------------------- ### Create a Tenant Source: https://github.com/zonastery/bursar/blob/main/README.md Initialize a new tenant using the Bursar CLI. ```bash bursar tenant create acme --id 018f7f5f-7b4a-7000-8000-000000000001 ``` -------------------------------- ### Initialize Bursar environment Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/07_credit_tiers_and_expiry.ipynb Sets up the Postgres store and initializes the user account with a pro plan and initial purchased credits. ```python from decimal import Decimal from datetime import UTC, datetime, timedelta from time import sleep from bursar.metrics import UsageMetrics from shared import cleanup, base_config, publish_config, start_postgres_store, USER_ADA def completion(output=Decimal(500)): return UsageMetrics( operation="completion", measures={ "input_tokens": Decimal(1000), "output_tokens": output, "cache_read_tokens": Decimal(200), }, dimensions={"model": "gpt-4o"}, ) store, pgdata = start_postgres_store() bursar = publish_config(store, base_config()) bursar.accounts.on_account_created(USER_ADA, "signup") bursar.credits.set_user_plan(USER_ADA, "pro") bursar.credits.add_credits(USER_ADA, Decimal("100.00"), entry_type="purchase", idempotency_key="buy") print("ready") ``` -------------------------------- ### Install Bursar skill via CLI Source: https://github.com/zonastery/bursar/blob/main/docs/docs/agent-skills.mdx Use the Skills CLI to add the Bursar skill to your project or globally. ```bash npx skills add zonastery/bursar@bursar ``` ```bash npx skills add zonastery/bursar@bursar --global ``` -------------------------------- ### Initialize Bursar environment for lease testing Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/08_leases_and_financial_safety.ipynb Sets up a temporary Postgres store and configures a user with credits to prepare for lease operations. ```python from decimal import Decimal from time import sleep from bursar.metrics import UsageMetrics from shared import cleanup, base_config, publish_config, start_postgres_store, USER_ADA def execution(jobs=Decimal(1)): return UsageMetrics( operation="execution", measures={"jobs": jobs, "compute_seconds": Decimal(30)}, dimensions={"model": "gpt-4o"}, ) store, pgdata = start_postgres_store() bursar = publish_config(store, base_config()) bursar.accounts.on_account_created(USER_ADA, "signup") bursar.credits.set_user_plan(USER_ADA, "pro") bursar.credits.add_credits(USER_ADA, Decimal("100.00"), entry_type="purchase", idempotency_key="buy") print("ready") ``` -------------------------------- ### Tier Function Usage Source: https://github.com/zonastery/bursar/blob/main/docs/docs/concepts/expressions.mdx Example of tiered pricing logic where the function returns a rate based on the first threshold met. ```text tier(input_tokens, 10000, 5, 100000, 10, 20) # value < 10000 → 5 # value < 100000 → 10 # otherwise → 20 (default) ``` -------------------------------- ### Example JSON validation error output Source: https://github.com/zonastery/bursar/blob/main/samples/python/notebooks/13_cli_and_deployment.ipynb Shows the structured error format returned when validation fails with the --json flag. ```json { "valid": false, "errors": [ { "type": "decimal_string", "loc": ["pricing", "rate_cards", "standard", "operations", "completion", "rules", 0, "charge", "sum", "components", 0, "per_unit", "rate"], "msg": "must be a base-10 decimal string", "input": 0.0025 } ] } ``` -------------------------------- ### Initialize PostgresStore Source: https://github.com/zonastery/bursar/blob/main/docs/docs/guides/storage-backends.mdx Construct a tenant-bound PostgresStore using the database URL and tenant identifier. ```python store = PostgresStore(database_url, tenant_id=tenant_id) ``` ```ts const store = new PostgresStore({ postgres: databaseUrl, tenantId }); ``` -------------------------------- ### RTK Command Usage Examples Source: https://github.com/zonastery/bursar/blob/main/AGENTS.md Commonly used RTK-prefixed commands for Git, file operations, testing, building, and infrastructure management. ```bash # Git (59-80% savings) rtk git status rtk git diff rtk git log # Files & Search (60-75% savings) rtk ls rtk read rtk grep rtk find rtk diff # Test (90-99% savings) — shows failures only rtk pytest tests/ rtk cargo test rtk test # Build & Lint (80-90% savings) — shows errors only rtk tsc rtk lint rtk cargo build rtk prettier --check rtk mypy rtk ruff check # Analysis (70-90% savings) rtk err rtk log rtk json rtk summary rtk deps rtk env # GitHub (26-87% savings) rtk gh pr view rtk gh run list rtk gh issue list # Infrastructure (85% savings) rtk docker ps rtk kubectl get rtk docker logs # Package managers (70-90% savings) rtk pip list rtk pnpm install rtk npm run