Skip to main content
Get a usage summary for a billing period. Exposed via speko.usage.
const usage = await speko.usage.get();
console.log(usage.totalSessions, usage.totalMinutes, usage.totalCost);

speko.usage.get(params?)

Signature

speko.usage.get(params?: UsageQueryParams): Promise<UsageSummary>

UsageQueryParams

FieldTypeDescription
fromstring?ISO-8601 start date. Omit to default to the current billing start.
tostring?ISO-8601 end date. Omit to default to now.

Returns — UsageSummary

FieldTypeDescription
totalSessionsnumberDistinct sessions in range.
totalMinutesnumberTotal audio minutes billed.
totalCostnumberTotal cost in USD.
breakdownUsageByProvider[]Per-provider rollup (see below).
balanceMicroUsdstringCurrent organization balance in micro-USD (1_000_000 µ==1), string-encoded for JSON safety.
balanceUsdnumberSame balance, pre-divided for display.

UsageByProvider

FieldTypeDescription
providerstringUpstream provider id.
type'stt' | 'llm' | 'tts'Modality.
metricstringThe billable metric (e.g. minutes, characters, tokens).
keySource'BYOK' | 'MANAGED'BYOK = customer key, no Speko margin. MANAGED = platform key, billed to org.
quantitynumberBilled quantity in the metric’s unit.
costnumberCost in USD.

Example: last 24 hours

const now = new Date();
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);

const usage = await speko.usage.get({
  from: yesterday.toISOString(),
  to: now.toISOString(),
});

for (const row of usage.breakdown) {
  console.log(`${row.type}\t${row.provider}\t${row.quantity}${row.metric}\t$${row.cost}`);
}