unitpay.usage.track; for firehose volumes, use the stateful UnitPayIngestion batcher.
unitpay.usage.track
Tracks one billable event, or an array of them in a single request. Also exposed asunitpay.track(...).
Parameters — TrackEventInput | TrackEventInput[]:
The customer the event belongs to.
The billable event, e.g.
ai-generation or api-call.How much usage to record.
Arbitrary event metadata for aggregation and filtering.
ISO-8601 event time. Defaults to now if omitted.
Dedupe key so retries don’t double-count.
Promise<TrackEventResult> with accepted: number, rejected: number, and optional rejections ({ index, reason, message }[]).
UnitPayIngestion
A separate, stateful client for high-throughput pipelines. Events are buffered and auto-flushed on an interval or when the batch fills; retries and buffer overflow are handled for you. Construct it once and keep it alive for the process lifetime. Constructor —UnitPayIngestionConfig:
Your secret key (
upay_sk_…).Flush on a timer. Set
false to flush only manually.How often the timer flushes the buffer.
Flush immediately once the buffer reaches this size.
Hard cap; the oldest event is dropped on overflow (surfaced via
onFlushError).Retries on
5xx / network errors before events go back in the buffer.Per-request timeout in ms.
Called when a flush fails or an event is dropped.
track(event)— buffer one event (TrackEventParams); non-blocking. Fills inquantity,timestamp, andidempotencyKeyif omitted.flush()— force-flush the buffer now. ReturnsPromise<FlushResult>({ accepted, rejected, rejections }).check(params)— synchronous entitlement check, bypassing the buffer. Takes{ customerId, featureSlug, requestedUsage? }, returnsPromise<CheckResponse>({ access: boolean, deniedReason? }).shutdown()— stop the timer and flush what’s left. Call on process exit.bufferSize— current number of buffered events.
See also
Customers & subscriptions
Read who you’re billing.
Errors & pagination
Typed errors and retry behavior.