- Documentation
- API References
- Integrations
- Templates
- Blog
- FAQ
- GitHub
- Getting started
Add-ons
Analytics
Billable metrics
Coupons
Credit notes
Customer usage
Customers
Events
Fees
Invoices
Organizations
Plans
Resources
Subscriptions
Taxes
Wallets
Webhook endpoints
Webhooks
API Reference
Create a billable metric
This endpoint creates a new billable metric representing a pricing component of your application.
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Name of the billable metric.
Unique code used to identify the billable metric associated with the API request. This code associates each event with the correct metric.
Internal description of the billable metric.
Defines if the billable metric is persisted billing period over billing period.
- If set to
true
: the accumulated number of units calculated from the previous billing period is persisted to the next billing period. - If set to
false
: the accumulated number of units is reset to 0 at the end of the billing period. - If not defined in the request, default value is
false
.
Property of the billable metric used for aggregating usage data. This field is not required for count_agg
.
Aggregation method used to compute usage for this billable metric.
Parameter exclusively utilized in conjunction with the weighted_sum
aggregation type. It serves to adjust the aggregation result by assigning weights and proration to the result based on time intervals. When this field is not provided, the default time interval is assumed to be in seconds
.
Group with one or two dimensions, used to apply differentiated pricing based on additional properties of the billable metric.
Name of the event property used to group values.
Array of strings or objects representing all possible values.
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
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": "Storage",
"code": "storage",
"description": "GB of storage used in my application",
"aggregation_type": "sum_agg",
"recurring": false,
"field_name": "gb",
"weighted_interval": "seconds",
"filters": [
{
"key": "region",
"values": ["us-east-1", "us-east-2", "eu-west-1"]
}
]
}
}'
{
"billable_metric": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"name": "Storage",
"code": "storage",
"description": "GB of storage used in my application",
"recurring": true,
"created_at": "2022-09-14T16:35:31Z",
"field_name": "gb",
"aggregation_type": "sum_agg",
"weighted_interval": "seconds",
"group": {
"key": "region",
"values": [
"us-east-1",
"us-east-2",
"eu-west-1"
]
},
"filters": [
{
"key": "region",
"values": [
"us-east-1"
]
}
],
"active_subscriptions_count": 4,
"draft_invoices_count": 10,
"plans_count": 4
}
}
Authorizations
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Body
Name of the billable metric.
Unique code used to identify the billable metric associated with the API request. This code associates each event with the correct metric.
Internal description of the billable metric.
Defines if the billable metric is persisted billing period over billing period.
- If set to
true
: the accumulated number of units calculated from the previous billing period is persisted to the next billing period. - If set to
false
: the accumulated number of units is reset to 0 at the end of the billing period. - If not defined in the request, default value is
false
.
Property of the billable metric used for aggregating usage data. This field is not required for count_agg
.
Aggregation method used to compute usage for this billable metric.
count_agg
, sum_agg
, max_agg
, unique_count_agg
, weighted_sum_agg
, latest_agg
Parameter exclusively utilized in conjunction with the weighted_sum
aggregation type. It serves to adjust the aggregation result by assigning weights and proration to the result based on time intervals. When this field is not provided, the default time interval is assumed to be in seconds
.
seconds
Group with one or two dimensions, used to apply differentiated pricing based on additional properties of the billable metric.
Name of the event property used to group values.
Array of strings or objects representing all possible values.
Filter key to add to the event properties payload
List of possible filter values
Response
Unique identifier of the billable metric created by Lago.
Name of the billable metric.
Unique code used to identify the billable metric associated with the API request. This code associates each event with the correct metric.
Internal description of the billable metric.
Defines if the billable metric is persisted billing period over billing period.
- If set to
true
: the accumulated number of units calculated from the previous billing period is persisted to the next billing period. - If set to
false
: the accumulated number of units is reset to 0 at the end of the billing period. - If not defined in the request, default value is
false
.
Creation date of the billable metric.
Property of the billable metric used for aggregating usage data. This field is not required for count_agg
.
Aggregation method used to compute usage for this billable metric.
count_agg
, sum_agg
, max_agg
, unique_count_agg
, weighted_sum_agg
, latest_agg
Parameter exclusively utilized in conjunction with the weighted_sum
aggregation type. It serves to adjust the aggregation result by assigning weights and proration to the result based on time intervals. When this field is not provided, the default time interval is assumed to be in seconds
.
seconds
Group with one or two dimensions, used to apply differentiated pricing based on additional properties of the billable metric.
Name of the event property used to group values.
Array of strings or objects representing all possible values.
Filter key to add to the event properties payload
List of possible filter values
Number of active subscriptions using this billable metric.
Number of draft invoices for which this billable metric is listed as an invoice item.
Number of plans using this billable metric.
Was this page helpful?
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
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": "Storage",
"code": "storage",
"description": "GB of storage used in my application",
"aggregation_type": "sum_agg",
"recurring": false,
"field_name": "gb",
"weighted_interval": "seconds",
"filters": [
{
"key": "region",
"values": ["us-east-1", "us-east-2", "eu-west-1"]
}
]
}
}'
{
"billable_metric": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"name": "Storage",
"code": "storage",
"description": "GB of storage used in my application",
"recurring": true,
"created_at": "2022-09-14T16:35:31Z",
"field_name": "gb",
"aggregation_type": "sum_agg",
"weighted_interval": "seconds",
"group": {
"key": "region",
"values": [
"us-east-1",
"us-east-2",
"eu-west-1"
]
},
"filters": [
{
"key": "region",
"values": [
"us-east-1"
]
}
],
"active_subscriptions_count": 4,
"draft_invoices_count": 10,
"plans_count": 4
}
}