Skip to content
Join our SlackContact usGet started

Create Pricing Metric

client.PricingMetrics.New(ctx, body) (*PricingMetricResource, error)
post/pricing-metrics

Create Pricing Metric

ParametersExpand Collapse
body PricingMetricNewParams

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

type PricingMetricNewParamsAggregationSum struct{…}

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

AggregationType Sum
Accepts one of the following:
const SumSum Sum = "sum"
ValueField string

Field to sum over.

type PricingMetricNewParamsAggregationCount struct{…}

Computes the number of usage events with the specified event_name.

AggregationType Count
Accepts one of the following:
const CountCount Count = "count"
type PricingMetricNewParamsAggregationMax struct{…}

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

AggregationType Max
Accepts one of the following:
const MaxMax Max = "max"
ValueField string

Field to get the max value of.

type PricingMetricNewParamsAggregationLast struct{…}

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

AggregationType Last
Accepts one of the following:
const LastLast Last = "last"
ValueField string

Field to get the last value of.

type PricingMetricNewParamsAggregationCustom struct{…}

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

AggregationType Custom
Accepts one of the following:
const CustomCustom Custom = "custom"
CustomExpression string

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

EventName param.Field[string]

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

Name param.Field[string]

The name of the pricing metric.

Unit param.Field[string]

Unit of measurement for the pricing metric.

Dimensions param.Field[[]string]optional

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

ReturnsExpand Collapse
type PricingMetricResource struct{…}
ID string

The ID of the pricing metric.

Aggregation PricingMetricResourceAggregationUnion

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

Accepts one of the following:
type PricingMetricResourceAggregationSum struct{…}
AggregationType Sum
Accepts one of the following:
const SumSum Sum = "sum"
ValueField string

The field to sum over.

type PricingMetricResourceAggregationCount struct{…}
AggregationType Count
Accepts one of the following:
const CountCount Count = "count"
type PricingMetricResourceAggregationMax struct{…}
AggregationType Max
Accepts one of the following:
const MaxMax Max = "max"
ValueField string

The field to get the max value of.

type PricingMetricResourceAggregationLast struct{…}
AggregationType Last
Accepts one of the following:
const LastLast Last = "last"
ValueField string

The field to get the last value of.

EventName 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 []stringoptional

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

Create Pricing Metric
package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/-go"
  "github.com/stainless-sdks/-go/option"
)

func main() {
  client := lark.NewClient(
    option.WithAPIKey("My API Key"),
  )
  pricingMetricResource, err := client.PricingMetrics.New(context.TODO(), lark.PricingMetricNewParams{
    Aggregation: lark.PricingMetricNewParamsAggregationUnion{
      OfSum: &lark.PricingMetricNewParamsAggregationSum{
        ValueField: "compute_hours",
      },
    },
    EventName: "job_completed",
    Name: "Compute Hours",
    Unit: "hours",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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"
  ]
}