Request Body
Human-readable name for the meter. Example: "API Usage Meter"
Name of the event to track. Must match the event name sent via the events API. Example: "api_request"
Defines how to aggregate the usage events. Show aggregation properties
Aggregation method to apply. Options: "COUNT", "SUM", "MAX", "UNIQUE_COUNT", "LATEST"
Property name in event data to aggregate (required for SUM, MAX, LATEST). Example: "tokens"
Optional CEL expression to compute per-event quantity from event properties. When set, replaces field-based extraction. Example: "token * duration * pixel"
Decimal multiplier to apply to the aggregated value. Example: "1.5"
Window size for bucketed aggregations. Options: "HOUR", "DAY", "MONTH"
Property name to group by before aggregating (currently only supported for MAX with bucket_size). Example: "user_id"
Array of filters to apply before aggregation. Property name in event data to filter on. Example: "region"
Array of values to match (OR condition). Example: ["us-east-1", "us-west-2"]
Determines when usage resets. Options: "BILLING_PERIOD", "NEVER"
Response
Unique identifier for the meter. Example: "meter_550e8400e29b41d4a716446655440000"
Human-readable name for the meter.
Tenant ID that owns this meter.
Name of the event being tracked.
Aggregation configuration.
Array of filters applied to events.
Usage reset configuration.
Status of the meter. Values: "published", "draft", "archived"
ISO 8601 timestamp when the meter was created.
ISO 8601 timestamp when the meter was last updated.
Example Request
curl --request POST \
--url https://api.flexprice.io/v1/meters \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"name": "API Usage Meter",
"event_name": "api_request",
"aggregation": {
"type": "COUNT"
},
"filters": [
{
"key": "method",
"values": ["GET", "POST"]
}
],
"reset_usage": "BILLING_PERIOD"
}'
Example Response
{
"id" : "meter_550e8400e29b41d4a716446655440000" ,
"name" : "API Usage Meter" ,
"tenant_id" : "tenant_123" ,
"event_name" : "api_request" ,
"aggregation" : {
"type" : "COUNT"
},
"filters" : [
{
"key" : "method" ,
"values" : [ "GET" , "POST" ]
}
],
"reset_usage" : "BILLING_PERIOD" ,
"status" : "published" ,
"created_at" : "2024-03-20T15:04:05Z" ,
"updated_at" : "2024-03-20T15:04:05Z"
}