vevee.periodUsage()GET /api/v1-16/usage/periodsk_live_
SDK 1.16+. Returns what a user consumed in one period, summed from their events and split per event type. Use it to audit a finished period, for example to build an invoice for last month. usage() is unchanged and still reads the live counters of the open period.
Signature
periodUsage(
userId: string,
options: {
period: 'current' | 'previous' | string; // string = an ISO 8601 instant
event?: string; // exact type, or a prefix ending in '*'
},
): Promise<PeriodUsageResponseData>Parameters
| Name | Type | Description | |
|---|---|---|---|
userId | required | string | End-user ID. Aliases are resolved, and the id used is returned as canonicalId. |
period | required | string | "current", "previous", or an ISO 8601 instant such as "2026-10-15". An instant selects the period that contains it. |
event | optional | string | Only count one event type ("report.run") or a family with a trailing star ("report.*"). |
Response
interface PeriodUsageResponseData {
userId: string; // the id you passed
canonicalId: string; // the id after alias resolution
period: {
start: string; // ISO 8601
end: string | null; // null for a lifetime plan
};
events: { // one entry per event type, sorted by event type
event: string;
events: number; // how many events
quantity: number; // summed quantity
costCents: number; // summed cost
byStatus: Partial<Record<
'matched' | 'matched_credits_only' | 'unmatched' | 'blocked' | 'no_subscription' | 'released',
{ events: number; quantity: number; costCents: number }
>>;
}[];
}Example
const last = await vevee.periodUsage('org_1', {
period: 'previous',
event: 'report.*',
});
console.log(last.period);
// { start: '2026-10-01T00:00:00.000Z', end: '2026-11-01T00:00:00.000Z' }
for (const e of last.events) {
console.log(e.event, e.quantity, e.costCents, e.byStatus.blocked?.events ?? 0);
}How the numbers are built
- Totals are summed from events, not from limit counters. Counters are enforcement state that a plan change or a customer merge can rewrite; events are not.
- Totals are per event type, not per limit group. The
byStatussplit shows how each event was treated when it was recorded. blockedmeans the event pushed a limit group over its quota and credits did not cover the gap. It is still stored and still counted here, so you can see what the user tried to use beyond the limit.releasedrows are reservations that were released (byrelease()or the TTL sweep). They are listed underbyStatus.releasedbut are not counted in the top-levelevents,quantityandcostCents. An event type with only released rows still appears, with zero totals.- Period bounds follow the user's current plan period rules, applied to the date you ask about.
- Rows read equal the user's events in that period, and only when you call this route. Nothing else pays for it, so call it for audits and invoices rather than on every page view.
Errors
requires_secret_key- apk_*key throws this before any request is sent. Secret key only.invalid_key(401)subscription_not_found(404) - the user has no active subscription.invalid_request(400) when:periodispreviousbut the user is still in their first period;periodis an instant in the future;periodis an instant before the subscription started;- the plan is lifetime and
periodis anything other thancurrent; periodis notcurrent,previousor an ISO 8601 instant.