How preburn/preburn works
Preburn is a margin-control service for AI products: a customer’s app checks a proposed call, receives an allow/route/cap/deny decision, calls its provider directly, then reports measured usage. The service prices usage, records revenue and cost, and uses customer margin signals and policies to guide decisions; a dashboard manages configuration and reviews outcomes. The README documents the Postgres, Valkey, and worker roles. Sampled route excerpts support several admin and reporting surfaces, but most internal wiring is inferred only where the README explicitly describes it.
Main entry points: api.go HTTP API · check.go Check decision · report_routes.go Usage report · worker.go Background worker
Components 20
Runtime decisions
- HTTP API
internal/httpapi/api.go - Check decision
internal/decisions/check.go - Usage report
internal/decisions/report_routes.go - Release reservation
internal/decisions/release.go - Policy rules
internal/policies/resolution.go
Pricing and margin
- Usage pricing
internal/pricing/rating.go - Revenue records
internal/revenue/service.go - Cost ledger
internal/ledger/entries.go - Customer records
internal/customers/service.go - Margin signals
internal/signals/signals.go - Plans and allowances
internal/plans/service.go
Operations and state
- Postgres
- Valkey counters
- Background worker
internal/app/worker.go
Dashboard and access
- Dashboard API
internal/dashboard/overview_routes.go - Dashboard UI
web/src/features/overview/overview-page.tsx - Policy editor
web/src/features/policies/policy-editor.tsx - Members and keys
internal/members/routes.go
Other components
- Customer app
- AI provider
Connections 18
- Customer app → HTTP API: checks and reports
- Customer app → AI provider: calls directly
- HTTP API → Check decision: dispatches checks
- HTTP API → Usage report: dispatches reports
- HTTP API → Release reservation: dispatches releases
- Check decision → Usage pricing: prices estimate
- Check decision → Margin signals: computes margin
- Check decision → Policy rules: applies policy
- Usage report → Usage pricing: prices usage
- Usage report → Cost ledger: records cost
- Revenue records → Customer records: creates unknown
- Dashboard UI → Dashboard API: requests data
- Policy editor → HTTP API: manages policies
- Members and keys → Postgres: stores access state
- HTTP API → Postgres: reads and writes
- HTTP API → Valkey counters: reads and writes counters
- Background worker → Postgres: maintains records
- Background worker → Valkey counters: repairs counters