Build a hybrid pricing and billing system like Segment, the Customer Data Platform leader, based on subscription plans, with a usage-based component that makes your revenue grow with your users.

Pricing structure

Segment offers three pricing plans, called ‘Free’, ‘Team’ and ‘Business’. As the latter has a custom pricing, we will focus on the first two plans.
PlanFree planTeam plan
Subscription Fee$0/month$120/month
Base Consumption (included)1,000 MTUs10,000 MTUs
Consumption (10k-25k MTUs)n/a$0.012/month/MTU
Consumption (25k-100k MTUs)n/a$0.011/month/MTU
Consumption (100k+ MTUs)n/a$0.010/month/MTU
Trial Periodn/a14 days
The usage-based component in Segment’s pricing is related to monthly tracked users (MTUs), namely the number of unique users whose data is stored on the platform each month.

Get started

1

Set up Lago

LAGO_URL="https://api.getlago.com"
API_KEY="__API_KEY__"
2

Create a billable metric

Create a billable metric to track unique users with deduplication.
  1. Set the aggregation_type to unique_count_agg for counting unique users
  2. Set the field_name to user_id to identify individual users
  3. Set recurring to false for metered billing
curl --location --request POST "$LAGO_URL/api/v1/billable_metrics" \
  --header 'Authorization: Bearer __API_KEY__' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "billable_metric": {
      "name": "Monthly Tracked Users",
      "code": "__BILLABLE_METRIC_CODE__",
      "description": "Unique users tracked monthly",
      "aggregation_type": "unique_count_agg",
      "field_name": "user_id",
      "recurring": false
    }
  }'
3

Create a plan

Create a Team plan with subscription fee and graduated usage charges.
  1. Set the amount_cents to 12000 for $120 monthly subscription
  2. Set pay_in_advance to true for upfront payment
  3. Set trial_period to 14 days for the trial period
  4. Configure graduated_ranges with Segment’s tiered pricing structure
curl --location --request POST "$LAGO_URL/api/v1/plans" \
  --header 'Authorization: Bearer __API_KEY__' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "plan": {
      "name": "Segment Team Plan",
      "code": "__PLAN_CODE__",
      "interval": "monthly",
      "description": "Team plan with subscription and graduated usage",
      "amount_cents": 12000,
      "amount_currency": "USD",
      "pay_in_advance": true,
      "trial_period": 14,
      "charges": [
        {
          "billable_metric_code": "__BILLABLE_METRIC_CODE__",
          "charge_model": "graduated",
          "properties": {
            "graduated_ranges": [
              {
                "from_value": 0,
                "to_value": 10000,
                "flat_amount": "0",
                "per_unit_amount": "0"
              },
              {
                "from_value": 10001,
                "to_value": 25000,
                "flat_amount": "0",
                "per_unit_amount": "0.012"
              },
              {
                "from_value": 25001,
                "to_value": 100000,
                "flat_amount": "0",
                "per_unit_amount": "0.011"
              },
              {
                "from_value": 100001,
                "to_value": null,
                "flat_amount": "0",
                "per_unit_amount": "0.010"
              }
            ]
          }
        }
      ]
    }
  }'
4

Create a customer

Create a customer with a unique external_id.
curl --location --request POST "$LAGO_URL/api/v1/customers" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "customer": {
      "external_id": "__EXTERNAL_CUSTOMER_ID__",
      "name": "Acme Inc",
      "email": "john@acme.com",
      "currency": "USD",
      "timezone": "America/New_York"
    }
  }'
Refer to the API reference to create a customer.
5

Create a subscription

Create a subscription for the customer with the plan’s code.
curl --location --request POST "$LAGO_URL/api/v1/subscriptions" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "subscription": {
      "external_customer_id": "__EXTERNAL_CUSTOMER_ID__",
      "plan_code": "__PLAN_CODE__",
      "external_id": "__EXTERNAL_SUBSCRIPTION_ID__"
    }
  }'
Refer to the API reference to create a subscription.Refer to API reference and guide on assigning plans in the documentation.
6

Ingest usage via events

Send usage events to Lago to track usage.
  1. Reference your billable metric with code
  2. Reference the customer’s subscription with external_subscription_id
  3. Include usage and filters data in properties
curl --location --request POST "$LAGO_URL/api/v1/events" \
  --header 'Authorization: Bearer __API_KEY__' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "event": {
      "transaction_id": "__TRANSACTION_ID__",
      "code": "__BILLABLE_METRIC_CODE__",
      "external_subscription_id": "__EXTERNAL_SUBSCRIPTION_ID__",
      "properties": {
        "user_id": "user_id_001"
      }
    }
  }'
Refer to the API reference to create an event.
7

Monitor current usage

Track real-time customer usage for the current billing period.
curl --location --request GET "$LAGO_URL/api/v1/customers/__EXTERNAL_CUSTOMER_ID__/current_usage?external_subscription_id=__EXTERNAL_SUBSCRIPTION_ID__" \
--header 'Authorization: Bearer __API_KEY__' \
--header 'Content-Type: application/json'
Refer to the API reference to get the current usage.

Wrap-up

Hybrid pricing plans are very popular among SaaS, API, fintech and data companies like Segment. With Lago, you can easily adapt this template to create your own hybrid pricing plan, using some of our most popular features:
  • Plan models, including monthly/yearly plans that can be paid in advance or in arrears;
  • Billable metrics, including multiple aggregation types; and
  • Charges, including our graduated pricing model (and more).
Give it a try, click here to get started!