ConfigsApr 10, 2026·2 min read

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.

AI
AI Open Source · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

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

# 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

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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets