Skip to content
Join our SlackContact usGet started

Create Pricing Metric

pricing_metrics.create(PricingMetricCreateParams**kwargs) -> PricingMetricResource
post/pricing-metrics

Create Pricing Metric

ParametersExpand Collapse
aggregation: Aggregation

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

Accepts one of the following:
class AggregationSumAggregationPricingMetricInterface:

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

aggregation_type: Literal["sum"]
Accepts one of the following:
"sum"
value_field: str

Field to sum over.

class AggregationCountAggregationPricingMetricInterface:

Computes the number of usage events with the specified event_name.

aggregation_type: Literal["count"]
Accepts one of the following:
"count"
class AggregationMaxAggregationPricingMetricInterface:

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

aggregation_type: Literal["max"]
Accepts one of the following:
"max"
value_field: str

Field to get the max value of.

class AggregationLastAggregationPricingMetricInterface:

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

aggregation_type: Literal["last"]
Accepts one of the following:
"last"
value_field: str

Field to get the last value of.

class AggregationCustomAggregationPricingMetricInterface:

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

aggregation_type: Literal["custom"]
Accepts one of the following:
"custom"
custom_expression: str

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

event_name: str

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

name: str

The name of the pricing metric.

unit: str

Unit of measurement for the pricing metric.

dimensions: Optional[SequenceNotStr[str]]

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

ReturnsExpand Collapse
class PricingMetricResource:
id: str

The ID of the pricing metric.

aggregation: Aggregation

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

Accepts one of the following:
class AggregationSumAggregationPricingMetricResource:
aggregation_type: Literal["sum"]
Accepts one of the following:
"sum"
value_field: str

The field to sum over.

class AggregationCountAggregationPricingMetricResource:
aggregation_type: Literal["count"]
Accepts one of the following:
"count"
class AggregationMaxAggregationPricingMetricResource:
aggregation_type: Literal["max"]
Accepts one of the following:
"max"
value_field: str

The field to get the max value of.

class AggregationLastAggregationPricingMetricResource:
aggregation_type: Literal["last"]
Accepts one of the following:
"last"
value_field: str

The field to get the last value of.

event_name: str

The event name that the pricing metric is computed on.

name: str

The name of the pricing metric.

unit: str

The unit of the value computed by the pricing metric.

dimensions: Optional[List[str]]

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

Create Pricing Metric
from lark import Lark

client = Lark(
    api_key="My API Key",
)
pricing_metric_resource = client.pricing_metrics.create(
    aggregation={
        "aggregation_type": "sum",
        "value_field": "compute_hours",
    },
    event_name="job_completed",
    name="Compute Hours",
    unit="hours",
)
print(pricing_metric_resource.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"
  ]
}