Skip to main content
Usage events feed both billing paths: they deduct credits at track-time and meter usage for invoice-time aggregation. Track a few events per request with 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 as unitpay.track(...). ParametersTrackEventInput | TrackEventInput[]:
string
required
The customer the event belongs to.
string
required
The billable event, e.g. ai-generation or api-call.
number
default:"1"
How much usage to record.
Record<string, unknown>
Arbitrary event metadata for aggregation and filtering.
string
ISO-8601 event time. Defaults to now if omitted.
string
Dedupe key so retries don’t double-count.
ReturnsPromise<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. ConstructorUnitPayIngestionConfig:
string
required
Your secret key (upay_sk_…).
boolean
default:"true"
Flush on a timer. Set false to flush only manually.
number
default:"1000"
How often the timer flushes the buffer.
number
default:"100"
Flush immediately once the buffer reaches this size.
number
default:"10000"
Hard cap; the oldest event is dropped on overflow (surfaced via onFlushError).
number
default:"3"
Retries on 5xx / network errors before events go back in the buffer.
number
default:"30000"
Per-request timeout in ms.
(error, events) => void
Called when a flush fails or an event is dropped.
string
typeof fetch
Methods
  • track(event) — buffer one event (TrackEventParams); non-blocking. Fills in quantity, timestamp, and idempotencyKey if omitted.
  • flush() — force-flush the buffer now. Returns Promise<FlushResult> ({ accepted, rejected, rejections }).
  • check(params) — synchronous entitlement check, bypassing the buffer. Takes { customerId, featureSlug, requestedUsage? }, returns Promise<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.