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

NameTypeDescription
userIdrequiredstringEnd-user ID. Aliases are resolved, and the id used is returned as canonicalId.
periodrequiredstring"current", "previous", or an ISO 8601 instant such as "2026-10-15". An instant selects the period that contains it.
eventoptionalstringOnly 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 byStatus split shows how each event was treated when it was recorded.
  • blocked means 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.
  • released rows are reservations that were released (by release() or the TTL sweep). They are listed under byStatus.released but are not counted in the top-level events, quantity and costCents. 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 - a pk_* 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:
    • period is previous but the user is still in their first period;
    • period is an instant in the future;
    • period is an instant before the subscription started;
    • the plan is lifetime and period is anything other than current;
    • period is not current, previous or an ISO 8601 instant.