Skip to content
Join our SlackContact usGet started

Create Usage Event

client.usageEvents.create(UsageEventCreateParams { data, event_name, idempotency_key, 2 more } body, RequestOptionsoptions?): UsageEventCreateResponse
post/usage-events

Create Usage Event

ParametersExpand Collapse
body: UsageEventCreateParams { data, event_name, idempotency_key, 2 more }
data: Record<string, string | number>

The data of the usage event. This should contain any data that is needed to aggregate the usage event.

Accepts one of the following:
string
number
event_name: string

The name of the event. This is used by pricing metrics to aggregate usage events.

idempotency_key: string

The idempotency key for the usage event. This ensures that the same event is not processed multiple times.

subject_id: string

The ID or external ID of the subject that the usage event is for.

timestamp?: string | null

The timestamp of the usage event. It is highly recommended to provide a timestamp. If not provided, the current timestamp will be used.

formatdate-time
ReturnsExpand Collapse
UsageEventCreateResponse = unknown
Create Usage Event
import Lark from 'lark-billing';

const client = new Lark({
  apiKey: 'My API Key',
});

const usageEvent = await client.usageEvents.create({
  data: { compute_hours: '100.5', instance_type: 't2.micro', region: 'us-east-1' },
  event_name: 'job_completed',
  idempotency_key: '168fbd3a-4d39-4db3-a204-15e014857d10',
  subject_id: 'subj_VyX6Q96h5avMho8O7QWlKeXE',
  timestamp: '2025-12-03T22:13:28.294419+00:00',
});

console.log(usageEvent);
{}
Returns Examples
{}