Why Billing as Code?
Type Safety
Catch pricing errors at compile time with full TypeScript inference
Version Control
Track pricing changes with Git, enabling rollback and audit trails
Single Source of Truth
Define features, plans, and pricing in one place - no dashboard configuration
CI/CD Integration
Deploy pricing changes through your existing pipeline with
revstack pushConfiguration Structure
Your billing configuration lives inrevstack.config.ts (or within a revstack/ directory for larger projects):
defineConfig function is a type-safe identity function that returns your configuration as-is while providing full TypeScript inference.
Defining Features
Features (also called entitlements) represent the capabilities your users can access. UsedefineFeature to define them:
revstack/features.ts
Feature Types
The feature type determines how access is checked:
boolean: On/off flag (e.g., SSO Access, Custom Domain)static: Fixed numeric limit included in plan (e.g., 5 Seats)metered: Usage-based, tracked over time (e.g., API Calls, AI Tokens)
Measurement unit:
count, bytes, seconds, tokens, requests, or customDefining Plans
Plans define what customers purchase. UsedefinePlan with a generic type parameter for compile-time feature validation:
revstack/plans.ts
Plan Types
free: No payment required (e.g., default guest plan, starter tier)paid: Requires active payment method and subscriptioncustom: Enterprise/B2B contracts where checkout redirects to “Contact Sales”
Overage Configuration
For metered features with soft limits (is_hard_limit: false), define overage pricing:
Defining Add-ons
Add-ons let customers purchase additional capacity or features on top of their plan:revstack/addons.ts
Add-on Feature Modification Types
increment: Adds to the base plan limit (e.g., plan has 5 seats + addon adds 10 = 15 total)set: Overrides the base plan limit completely (e.g., plan has 5 seats, addon sets to 100)
Defining Discounts
Discounts (coupons) offer temporary price reductions:revstack/coupons.ts
Type Safety Benefits
When you passtypeof features to definePlan or defineAddon, TypeScript enforces:
Deploying Configuration
Push your configuration to Revstack Cloud:The CLI validates your configuration with Zod schemas before pushing, catching errors like invalid billing intervals or missing required fields.
Next Steps
Entitlements
Learn how to check feature access in your application
Usage Metering
Track consumption for metered features