Commet
  • Precios
Iniciar SesiónRegistrarse
Check usage availability POSTSet current usage PUTTrack usage event POST
DocumentaciónRecursosConstruir con AIAPI ReferenceWebhooks

Track usage event

Track a usage event for a metered feature. Deducts from balance/credits if applicable.

POST
/usage/events

Track a usage event for a metered feature. Deducts from balance/credits if applicable.

Authorization

ApiKeyAuth
x-api-key<token>

In: header

Header Parameters

Idempotency-Key?string

Unique key used to safely retry this write for 24 hours without applying it twice.

Length1 <= length <= 200

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

featureCode*string
Match^[a-z0-9_]+$
Length1 <= length <= 50
customerId*string
Length1 <= length <= 200
eventId?string
Length1 <= length <= 200
timestamp?string
Formatdate-time
properties?array<>
Default[]
value?number
Range0 <= value
Default1
cacheReadTokens?integer
Range0 <= value <= 9007199254740991
cacheWriteTokens?integer
Range0 <= value <= 9007199254740991
model*string
Length1 <= length <= 200
inputTokens*integer
Range0 <= value <= 9007199254740991
outputTokens*integer
Range0 <= value <= 9007199254740991

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/usage/events" \  -H "Content-Type: application/json" \  -d '{    "featureCode": "string",    "customerId": "string",    "model": "string",    "inputTokens": 0,    "outputTokens": 0  }'
{  "id": "string",  "featureCode": "string",  "value": 0,  "customerId": "string",  "eventId": "string",  "ts": "2019-08-24T14:15:22Z",  "createdAt": "2019-08-24T14:15:22Z",  "properties": [    {      "property": "string",      "value": "string"    }  ],  "consumption": {    "model": "string",    "deducted": 0,    "remaining": 0,    "blocked": true  },  "object": "usage_event",  "livemode": true}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}
{  "error": {    "type": "string",    "code": "string",    "message": "string",    "param": "string",    "details": null,    "doc_url": "string"  }}

Set current usage PUT

Set a metered feature's usage to an exact value for the current period. Use the Idempotency-Key header to make retries safe.

Create webhook endpoint POST

Create a new webhook endpoint. The response includes the signing secret which is only returned once.