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.
VIDEO
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.
Plan Free plan Team plan Subscription Fee $0/month $120/month Base Consumption (included) 1,000 MTUs 10,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 Period n/a 14 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
Set up Lago
cURL
Python
Ruby
Javascript
Go
LAGO_URL = "https://api.getlago.com"
API_KEY = "__API_KEY__"
Create a billable metric
Create a billable metric to track unique users with deduplication.
Set the aggregation_type
to unique_count_agg
for counting unique users
Set the field_name
to user_id
to identify individual users
Set recurring
to false
for metered billing
cURL
Python
Ruby
JavaScript
Go
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
}
}'
Create a plan
Create a Team plan with subscription fee and graduated usage charges.
Set the amount_cents
to 12000
for $120 monthly subscription
Set pay_in_advance
to true
for upfront payment
Set trial_period
to 14
days for the trial period
Configure graduated_ranges
with Segment’s tiered pricing structure
cURL
Python
Ruby
JavaScript
Go
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"
}
]
}
}
]
}
}'
See all 49 lines
Create a customer
Create a customer with a unique external_id
.
cURL
Python
Ruby
Javascript
Go
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.
Create a subscription
Create a subscription for the customer with the plan’s code
.
cURL
Python
Ruby
Javascript
Go
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.
Ingest usage via events
Send usage events to Lago to track usage.
Reference your billable metric with code
Reference the customer’s subscription with external_subscription_id
Include usage and filters data in properties
cURL
Python
Ruby
JavaScript
Go
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.
Monitor current usage
Track real-time customer usage for the current billing period.
cURL
Python
Ruby
Javascript
Go
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!