Track usage event
curl --request POST \
--url https://commet.co/api/v1/usage/events \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"feature": "<string>",
"customerId": "<string>",
"timestamp": "<unknown>",
"properties": [],
"value": 1,
"model": "<string>",
"inputTokens": 4503599627370495,
"outputTokens": 4503599627370495
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
feature: '<string>',
customerId: '<string>',
timestamp: '<unknown>',
properties: [],
value: 1,
model: '<string>',
inputTokens: 4503599627370495,
outputTokens: 4503599627370495
})
};
fetch('https://commet.co/api/v1/usage/events', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://commet.co/api/v1/usage/events"
payload = {
"feature": "<string>",
"customerId": "<string>",
"timestamp": "<unknown>",
"properties": [],
"value": 1,
"model": "<string>",
"inputTokens": 4503599627370495,
"outputTokens": 4503599627370495
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://commet.co/api/v1/usage/events"
payload := strings.NewReader("{\n \"feature\": \"<string>\",\n \"customerId\": \"<string>\",\n \"timestamp\": \"<unknown>\",\n \"properties\": [],\n \"value\": 1,\n \"model\": \"<string>\",\n \"inputTokens\": 4503599627370495,\n \"outputTokens\": 4503599627370495\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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://commet.co/api/v1/usage/events")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"feature\": \"<string>\",\n \"customerId\": \"<string>\",\n \"timestamp\": \"<unknown>\",\n \"properties\": [],\n \"value\": 1,\n \"model\": \"<string>\",\n \"inputTokens\": 4503599627370495,\n \"outputTokens\": 4503599627370495\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://commet.co/api/v1/usage/events",
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([
'feature' => '<string>',
'customerId' => '<string>',
'timestamp' => '<unknown>',
'properties' => [
],
'value' => 1,
'model' => '<string>',
'inputTokens' => 4503599627370495,
'outputTokens' => 4503599627370495
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"success": true,
"data": {
"id": "<string>",
"feature": "<string>",
"value": 123,
"customerId": "<string>",
"idempotencyKey": "<string>",
"ts": "2023-11-07T05:31:56Z",
"createdAt": "2023-11-07T05:31:56Z",
"properties": [
{
"property": "<string>",
"value": "<string>"
}
],
"object": "usage_event",
"livemode": true,
"consumption": {
"model": "credits",
"deducted": 123,
"remaining": 123,
"blocked": true,
"planCreditLimit": {
"credits": 0,
"interval": "day",
"spent": 0,
"remaining": 0,
"resetsAt": "2023-11-07T05:31:56Z"
},
"planBalanceLimit": {
"amount": 0,
"interval": "day",
"spent": 0,
"remaining": 0,
"resetsAt": "2023-11-07T05:31:56Z"
}
}
}
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}Usage
Track usage event
Track a usage event for a metered feature. Deducts from balance/credits if applicable.
POST
/
usage
/
events
Track usage event
curl --request POST \
--url https://commet.co/api/v1/usage/events \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"feature": "<string>",
"customerId": "<string>",
"timestamp": "<unknown>",
"properties": [],
"value": 1,
"model": "<string>",
"inputTokens": 4503599627370495,
"outputTokens": 4503599627370495
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
feature: '<string>',
customerId: '<string>',
timestamp: '<unknown>',
properties: [],
value: 1,
model: '<string>',
inputTokens: 4503599627370495,
outputTokens: 4503599627370495
})
};
fetch('https://commet.co/api/v1/usage/events', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://commet.co/api/v1/usage/events"
payload = {
"feature": "<string>",
"customerId": "<string>",
"timestamp": "<unknown>",
"properties": [],
"value": 1,
"model": "<string>",
"inputTokens": 4503599627370495,
"outputTokens": 4503599627370495
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://commet.co/api/v1/usage/events"
payload := strings.NewReader("{\n \"feature\": \"<string>\",\n \"customerId\": \"<string>\",\n \"timestamp\": \"<unknown>\",\n \"properties\": [],\n \"value\": 1,\n \"model\": \"<string>\",\n \"inputTokens\": 4503599627370495,\n \"outputTokens\": 4503599627370495\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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://commet.co/api/v1/usage/events")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"feature\": \"<string>\",\n \"customerId\": \"<string>\",\n \"timestamp\": \"<unknown>\",\n \"properties\": [],\n \"value\": 1,\n \"model\": \"<string>\",\n \"inputTokens\": 4503599627370495,\n \"outputTokens\": 4503599627370495\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://commet.co/api/v1/usage/events",
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([
'feature' => '<string>',
'customerId' => '<string>',
'timestamp' => '<unknown>',
'properties' => [
],
'value' => 1,
'model' => '<string>',
'inputTokens' => 4503599627370495,
'outputTokens' => 4503599627370495
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"success": true,
"data": {
"id": "<string>",
"feature": "<string>",
"value": 123,
"customerId": "<string>",
"idempotencyKey": "<string>",
"ts": "2023-11-07T05:31:56Z",
"createdAt": "2023-11-07T05:31:56Z",
"properties": [
{
"property": "<string>",
"value": "<string>"
}
],
"object": "usage_event",
"livemode": true,
"consumption": {
"model": "credits",
"deducted": 123,
"remaining": 123,
"blocked": true,
"planCreditLimit": {
"credits": 0,
"interval": "day",
"spent": 0,
"remaining": 0,
"resetsAt": "2023-11-07T05:31:56Z"
},
"planBalanceLimit": {
"amount": 0,
"interval": "day",
"spent": 0,
"remaining": 0,
"resetsAt": "2023-11-07T05:31:56Z"
}
}
}
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}{
"success": false,
"code": "<string>",
"message": "<string>",
"details": "<unknown>"
}This reference describes API version
2026-05-18. Send Commet-Version: 2026-05-18 with your request.Encabezados
Cuerpo
application/json
- Option 1
- Option 2
¿Esta página le ayudó?