# Lago — Open Source Usage-Based Billing API > Lago is an open-source metering and billing engine for usage-based pricing, subscription management, invoicing, and payment orchestration. ## Install Save in your project root: ## Quick Use ```bash git clone https://github.com/getlago/lago.git cd lago docker compose up -d ``` Open `http://localhost:80` — access the Lago dashboard to configure billing plans and meters. ## Intro **Lago** is an open-source billing API for usage-based pricing models. It handles metering, subscription management, invoicing, and payment orchestration — replacing expensive SaaS billing platforms like Stripe Billing, Chargebee, or Zuora for companies that need flexibility and control. With 9.5K+ GitHub stars and AGPL-3.0 license, Lago powers billing for AI companies, API platforms, and SaaS products that charge based on consumption (API calls, tokens, compute hours, storage). ## What Lago Does Lago provides the complete billing infrastructure: - **Usage Metering**: Ingest events via API, aggregate by count, sum, max, unique count, or weighted sum - **Flexible Pricing**: Per-unit, graduated, package, percentage, and volume-based pricing models - **Subscription Management**: Create plans with recurring charges, add-ons, and trial periods - **Real-Time Invoicing**: Automatic invoice generation with PDF export and tax calculation - **Payment Orchestration**: Integrate with Stripe, GoCardless, Adyen for automatic payment collection - **Revenue Analytics**: Track MRR, churn, lifetime value, and usage trends - **Webhooks**: Real-time events for invoice created, payment succeeded/failed, subscription changes - **Multi-Currency**: Support for 150+ currencies with automatic conversion ### Ingesting Usage Events ```bash # Send a usage event via API curl -X POST https://api.lago.dev/api/v1/events \ -H "Authorization: Bearer $LAGO_API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"event\": { \"transaction_id\": \"tx_001\", \"external_subscription_id\": \"sub_123\", \"code\": \"api_calls\", \"timestamp\": $(date +%s), \"properties\": { \"tokens\": 1500 } } }" ``` ### Python SDK ```python from lago_python_client import Client client = Client(api_key="lago_api_key") # Create a billable metric client.billable_metrics.create({ "name": "API Calls", "code": "api_calls", "aggregation_type": "sum_agg", "field_name": "tokens" }) # Create a plan with usage-based pricing client.plans.create({ "name": "Pro Plan", "code": "pro", "interval": "monthly", "amount_cents": 4900, "charges": [{ "billable_metric_code": "api_calls", "charge_model": "graduated", "properties": { "graduated_ranges": [ {"from_value": 0, "to_value": 10000, "per_unit_amount": "0.001"}, {"from_value": 10001, "to_value": None, "per_unit_amount": "0.0005"} ] } }] }) ``` ## FAQ **Q: Is Lago suitable for AI/LLM billing?** A: Yes. Lago is specifically designed for usage-based billing — track tokens, API calls, compute hours, or any custom metric and bill accordingly. **Q: How does Lago compare to Stripe Billing?** A: Lago offers more flexible metering and pricing models, full self-hosting, and no percentage-of-revenue fees. Stripe Billing is easier to start with but less customizable for complex usage-based models. **Q: Can I self-host Lago?** A: Yes. Deploy with Docker Compose for a complete setup including PostgreSQL, Redis, and the web dashboard. **Q: What payment processors does Lago support?** A: Stripe, GoCardless, and Adyen. Payment collection is automatic based on generated invoices. ## Source & Thanks - GitHub: [getlago/lago](https://github.com/getlago/lago) — 9.5K+ ⭐ | AGPL-3.0 - Website: [getlago.com](https://www.getlago.com) - Docs: [docs.getlago.com](https://docs.getlago.com) ## 快速使用 ```bash git clone https://github.com/getlago/lago.git cd lago docker compose up -d ``` 打开 `http://localhost:80`,访问 Lago 仪表盘配置计费方案和计量器。 ## 简介 **Lago** 是一个开源的计费 API,专为按用量计费的定价模式设计。处理计量、订阅管理、发票和支付编排,替代 Stripe Billing、Chargebee 等昂贵的 SaaS 计费平台。 拥有 9.5K+ GitHub 星标和 AGPL-3.0 许可证,Lago 为 AI 公司、API 平台和按消费计费的 SaaS 产品提供计费基础设施。 ## 核心功能 - **用量计量**:通过 API 摄取事件,支持计数、求和、最大值等聚合方式 - **灵活定价**:按单位、阶梯、打包、百分比和按量定价模型 - **订阅管理**:创建包含周期性费用、附加组件和试用期的方案 - **实时发票**:自动生成发票,支持 PDF 导出和税费计算 - **支付编排**:集成 Stripe、GoCardless、Adyen 自动收款 ## 常见问题 **Q: Lago 适合 AI/LLM 计费吗?** A: 是的。Lago 专为按用量计费设计,可追踪 token、API 调用、计算时长等任何自定义指标。 **Q: 可以自托管吗?** A: 可以。使用 Docker Compose 部署,包含 PostgreSQL、Redis 和 Web 仪表盘。 ## 来源与致谢 - GitHub: [getlago/lago](https://github.com/getlago/lago) — 9.5K+ ⭐ | AGPL-3.0 - 官网: [getlago.com](https://www.getlago.com) --- Source: https://tokrepo.com/en/workflows/f9227c2e-3474-11f1-9bc6-00163e2b0d79 Author: AI Open Source