Skip to main content
POST
/
v0
/
billableMetrics
Create
curl --request POST \
  --url https://api.paygentic.io/v0/billableMetrics \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "description": "<string>",
  "merchantId": "<string>",
  "name": "<string>",
  "productId": "<string>",
  "unit": "<string>",
  "eventType": "<string>",
  "valueProperty": "<string>",
  "groupBy": {},
  "eventFrom": "2023-11-07T05:31:56Z"
}
'
import requests

url = "https://api.paygentic.io/v0/billableMetrics"

payload = {
"description": "<string>",
"merchantId": "<string>",
"name": "<string>",
"productId": "<string>",
"unit": "<string>",
"eventType": "<string>",
"valueProperty": "<string>",
"groupBy": {},
"eventFrom": "2023-11-07T05:31:56Z"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
description: '<string>',
merchantId: '<string>',
name: '<string>',
productId: '<string>',
unit: '<string>',
eventType: '<string>',
valueProperty: '<string>',
groupBy: {},
eventFrom: '2023-11-07T05:31:56Z'
})
};

fetch('https://api.paygentic.io/v0/billableMetrics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.paygentic.io/v0/billableMetrics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'description' => '<string>',
'merchantId' => '<string>',
'name' => '<string>',
'productId' => '<string>',
'unit' => '<string>',
'eventType' => '<string>',
'valueProperty' => '<string>',
'groupBy' => [

],
'eventFrom' => '2023-11-07T05:31:56Z'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.paygentic.io/v0/billableMetrics"

payload := strings.NewReader("{\n \"description\": \"<string>\",\n \"merchantId\": \"<string>\",\n \"name\": \"<string>\",\n \"productId\": \"<string>\",\n \"unit\": \"<string>\",\n \"eventType\": \"<string>\",\n \"valueProperty\": \"<string>\",\n \"groupBy\": {},\n \"eventFrom\": \"2023-11-07T05:31:56Z\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.paygentic.io/v0/billableMetrics")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"description\": \"<string>\",\n \"merchantId\": \"<string>\",\n \"name\": \"<string>\",\n \"productId\": \"<string>\",\n \"unit\": \"<string>\",\n \"eventType\": \"<string>\",\n \"valueProperty\": \"<string>\",\n \"groupBy\": {},\n \"eventFrom\": \"2023-11-07T05:31:56Z\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.paygentic.io/v0/billableMetrics")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"description\": \"<string>\",\n \"merchantId\": \"<string>\",\n \"name\": \"<string>\",\n \"productId\": \"<string>\",\n \"unit\": \"<string>\",\n \"eventType\": \"<string>\",\n \"valueProperty\": \"<string>\",\n \"groupBy\": {},\n \"eventFrom\": \"2023-11-07T05:31:56Z\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "bm_w9x0y1z2a3b4c5d6",
  "object": "billableMetric",
  "aggregation": "SUM",
  "createdAt": "2024-01-15T10:30:00Z",
  "description": "Total tokens consumed by Claude language model interactions",
  "merchantId": "org_e7f8g9h0i1j2k3l4",
  "name": "Claude Tokens",
  "productId": "prod_m5n6o7p8q9r0s1t2",
  "taxRate": 8.5,
  "unit": "tokens",
  "updatedAt": "2024-01-15T10:30:00Z"
}
{
"message": "The requested resource was not found",
"error": "not_found"
}
{
"message": "The requested resource was not found",
"error": "not_found"
}
{
"message": "The requested resource was not found",
"error": "not_found"
}
{
"message": "The requested resource was not found",
"error": "not_found"
}

Authorizations

Authorization
string
header
required

API key authentication

Body

application/json
aggregation
enum<string>
required

Aggregation calculation method for metric values.

Available options:
SUM,
COUNT,
AVG,
MIN,
MAX,
UNIQUE_COUNT,
LATEST
description
string
required

Explanatory text describing what the metric tracks and how it's used for billing. Sample values: 'Total tokens consumed by Claude language model interactions', 'Gigabytes of cloud storage utilized', 'Count of machine learning inference requests processed', 'Quantity of AI-generated images created', 'Compute hours spent training neural networks', 'Terabytes of data transferred'

merchantId
string
required

The unique identifier of the merchant organization associated with the billable metric.

Pattern: ^org_[a-zA-Z0-9]+$
name
string
required

Human-readable label identifying what this metric measures. Sample values: 'Claude Tokens', 'Storage Capacity', 'Model Inference Calls', 'Generated Images', 'Training Compute Hours', 'Data Transfer Volume'

productId
string
required

The unique identifier of the product associated with the billable metric.

Pattern: ^prod_[a-zA-Z0-9]+$
unit
string
required

Measurement unit used when aggregating this metric's values. Common examples: 'tokens', 'GB', 'calls', 'images', 'hours', 'TB', 'queries', 'requests'

eventType
string

CloudEvents type for meter routing. Links this billable metric to the metering service.

valueProperty
string

JSONPath to extract a numeric value from event data. Must start with $. (example: $.amount or $.payload.bytes). Required for SUM/AVG/MIN/MAX/LATEST aggregations.

Pattern: ^\$\.[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*$
groupBy
object

Map of dimension name to JSONPath for group-by queries. Each value must start with $. (example: $.region).

eventFrom
string<date-time>

Only count events after this timestamp. Used for meter versioning.

Response

Billable metric created successfully

id
string
required

Unique identifier for a billable metric

Pattern: ^bm_[a-zA-Z0-9]+$
object
enum<string>
default:billableMetric
required
Available options:
billableMetric
aggregation
enum<string>
required
Available options:
SUM,
COUNT,
AVG,
MIN,
MAX,
UNIQUE_COUNT,
LATEST
createdAt
string<date-time>
required
description
string
required
merchantId
string
required

Unique identifier for an organization

Pattern: ^org_[a-zA-Z0-9]+$
name
string
required
productId
string
required

Unique identifier for a product

Pattern: ^prod_[a-zA-Z0-9]+$
unit
string
required
updatedAt
string<date-time>
required
eventType
string | null
valueProperty
string | null
groupBy
object | null
eventFrom
string<date-time> | null