Usage-based pricing is the future of SaaS. But implementing it means tracking events, calculating invoices, handling proration, and managing subscriptions. Lago does all of this — open source, self-hostable, and with a clean API.
What Is Lago?
Lago is an open-source metering and billing platform. It tracks usage events, applies pricing models, generates invoices, and integrates with payment providers. Think Stripe Billing, but open source and designed specifically for usage-based pricing.
The Free Platform
Lago is completely free and open source:
- Usage metering: Track billable events in real-time
- Flexible pricing: Pay-as-you-go, tiered, volume, package pricing
- Subscriptions: Recurring billing with add-ons
- Invoicing: Automatic invoice generation
- Coupons and credits: Promotional pricing tools
- Webhooks: Real-time billing event notifications
- Payment integration: Stripe, GoCardless, Adyen
- REST API: Full programmatic control
Quick Start
Self-host with Docker:
git clone https://github.com/getlago/lago.git
cd lago
docker compose up -d
Or use Lago Cloud (free tier available).
Track usage events:
import { Client } from 'lago-javascript-client';
const lago = Client('your-api-key');
// Send usage events
await lago.events.createEvent({
event: {
transaction_id: 'txn_123',
external_customer_id: 'cust_456',
code: 'api_calls',
timestamp: Math.floor(Date.now() / 1000),
properties: {
tokens: 1500,
},
},
});
Define pricing:
# Create a billable metric
curl -X POST https://api.getlago.com/api/v1/billable_metrics \
-H 'Authorization: Bearer YOUR_KEY' \
-d '{
"billable_metric": {
"name": "API Calls",
"code": "api_calls",
"aggregation_type": "sum_agg",
"field_name": "tokens"
}
}'
# Create a plan with usage-based pricing
curl -X POST https://api.getlago.com/api/v1/plans \
-H 'Authorization: Bearer YOUR_KEY' \
-d '{
"plan": {
"name": "Pro Plan",
"code": "pro",
"interval": "monthly",
"amount_cents": 2900,
"charges": [{
"billable_metric_code": "api_calls",
"charge_model": "graduated",
"properties": {
"graduated_ranges": [
{"from_value": 0, "to_value": 10000, "per_unit_amount": "0", "flat_amount": "0"},
{"from_value": 10001, "to_value": null, "per_unit_amount": "0.001", "flat_amount": "0"}
]
}
}]
}
}'
Why Teams Choose Lago
An AI startup needed usage-based billing for API calls. Stripe Billing could not handle their pricing model (graduated tiers based on token count). Building custom billing took 2 months and was full of edge cases. After switching to Lago, they had accurate metering, automatic invoicing, and graduated pricing working in a day.
Who Is This For?
- SaaS companies with usage-based or consumption pricing
- AI/API companies billing per request, token, or compute unit
- Infrastructure companies with metered services
- Teams outgrowing Stripe Billing for complex pricing models
Start Billing
Lago handles the complexity of usage-based billing. Track events, apply pricing, generate invoices — all open source.
Need help with billing infrastructure? I build custom SaaS solutions — reach out to discuss your project.
Found this useful? I publish daily deep-dives into developer tools and APIs. Follow for more.
Top comments (0)