Skip to content
Join our SlackContact usGet started

Create Pricing Metric

client.pricingMetrics.create(PricingMetricCreateParams { aggregation, event_name, name, 2 more } body, RequestOptionsoptions?): PricingMetricResource { id, aggregation, event_name, 3 more }
post/pricing-metrics

Create Pricing Metric

ParametersExpand Collapse
body: PricingMetricCreateParams { aggregation, event_name, name, 2 more }
aggregation: SumAggregationPricingMetricInterface { aggregation_type, value_field } | CountAggregationPricingMetricInterface { aggregation_type } | MaxAggregationPricingMetricInterface { aggregation_type, value_field } | 2 more

The aggregation function used to compute the value of the pricing metric.

Accepts one of the following:
SumAggregationPricingMetricInterface { aggregation_type, value_field }

Computes the sum of the value_field over all usage events with the specified event_name.

aggregation_type: "sum"
Accepts one of the following:
"sum"
value_field: string

Field to sum over.

CountAggregationPricingMetricInterface { aggregation_type }

Computes the number of usage events with the specified event_name.

aggregation_type: "count"
Accepts one of the following:
"count"
MaxAggregationPricingMetricInterface { aggregation_type, value_field }

Computes the max value of the value_field over all usage events with the specified event_name.

aggregation_type: "max"
Accepts one of the following:
"max"
value_field: string

Field to get the max value of.

LastAggregationPricingMetricInterface { aggregation_type, value_field }

Computes the last value of the value_field over all usage events with the specified event_name.

aggregation_type: "last"
Accepts one of the following:
"last"
value_field: string

Field to get the last value of.

CustomAggregationPricingMetricInterface { aggregation_type, custom_expression }

Custom aggregation for use cases not supported by the other aggregation types. Please email team@uselark.ai to enable this feature.

aggregation_type: "custom"
Accepts one of the following:
"custom"
custom_expression: string

Custom expression to compute the pricing metric. Please email team@uselark.ai to enable this feature.

event_name: string

The name of the event that the pricing metric is computed on.

name: string

The name of the pricing metric.

unit: string

Unit of measurement for the pricing metric.

dimensions?: Array<string> | null

The dimensions by which the events are grouped to compute the pricing metric.

ReturnsExpand Collapse
PricingMetricResource { id, aggregation, event_name, 3 more }
id: string

The ID of the pricing metric.

aggregation: SumAggregationPricingMetricResource { aggregation_type, value_field } | CountAggregationPricingMetricResource { aggregation_type } | MaxAggregationPricingMetricResource { aggregation_type, value_field } | LastAggregationPricingMetricResource { aggregation_type, value_field }

The aggregation function used to compute the value of the pricing metric.

Accepts one of the following:
SumAggregationPricingMetricResource { aggregation_type, value_field }
aggregation_type: "sum"
Accepts one of the following:
"sum"
value_field: string

The field to sum over.

CountAggregationPricingMetricResource { aggregation_type }
aggregation_type: "count"
Accepts one of the following:
"count"
MaxAggregationPricingMetricResource { aggregation_type, value_field }
aggregation_type: "max"
Accepts one of the following:
"max"
value_field: string

The field to get the max value of.

LastAggregationPricingMetricResource { aggregation_type, value_field }
aggregation_type: "last"
Accepts one of the following:
"last"
value_field: string

The field to get the last value of.

event_name: string

The event name that the pricing metric is computed on.

name: string

The name of the pricing metric.

unit: string

The unit of the value computed by the pricing metric.

dimensions?: Array<string> | null

The dimensions by which the events are grouped to compute the pricing metric.

Create Pricing Metric
import Lark from 'lark-billing';

const client = new Lark({
  apiKey: 'My API Key',
});

const pricingMetricResource = await client.pricingMetrics.create({
  aggregation: { aggregation_type: 'sum', value_field: 'compute_hours' },
  event_name: 'job_completed',
  name: 'Compute Hours',
  unit: 'hours',
});

console.log(pricingMetricResource.id);
{
  "id": "pmtr_GlX5Tcm2HOn00CoRTFxw2Amw",
  "aggregation": {
    "aggregation_type": "sum",
    "value_field": "compute_hours"
  },
  "event_name": "job_completed",
  "name": "Compute Hours",
  "unit": "hours",
  "dimensions": [
    "string"
  ]
}
Returns Examples
{
  "id": "pmtr_GlX5Tcm2HOn00CoRTFxw2Amw",
  "aggregation": {
    "aggregation_type": "sum",
    "value_field": "compute_hours"
  },
  "event_name": "job_completed",
  "name": "Compute Hours",
  "unit": "hours",
  "dimensions": [
    "string"
  ]
}