Skip to main content
const { result, error } = await unprice.usage.record({
  idempotencyKey: "idem_123",
  eventSlug: "completions",
  customerId: "cus_1234567890",
  properties: {
    aiMessages: 1,
    aiGenerations: 2,
    aiTools: 3,
    inputTokens: 1840,
    outputTokens: 620,
    model: "gpt-4.1-mini"
  }
});

if (error) {
  console.error(error.message);
  return;
}

console.log(result);
{
  "accepted": true
}

Request

idempotencyKey
string
required
Logical key used to deduplicate the event.
eventSlug
string
required
The broad event kind configured in Unprice, for example completions.
customerId
string
The customer ID. Required when the API key has no default customer binding.
properties
object
required
Event properties used by meters. One async event can carry multiple measured fields, for example aiMessages, aiGenerations, aiTools, inputTokens, and outputTokens.
timestamp
number
Optional epoch-millisecond event timestamp.
usage.record does not block paid work. Use it for async metering, analytics, and invoice evidence, not for request-path spend enforcement. For async reporting, eventSlug names what happened. Each meter on matching features chooses which property to aggregate from that event. That lets one completions event update several features such as ai-messages, ai-generations, and ai-tools.