Skip to main content
Query the organization’s prepaid credit balance and walk the ledger of every credit movement. Exposed via speko.credits. Balances are in micro-USD (1_000_000 µ==1). The SDK also pre-divides to a float USD helper.
const { balanceUsd } = await speko.credits.getBalance();
if (balanceUsd < 0.5) showLowBalanceBanner();

speko.credits.getBalance()

Signature

speko.credits.getBalance(): Promise<OrganizationBalance>

Returns — OrganizationBalance

FieldTypeDescription
balanceMicroUsdstringCurrent balance as micro-USD, string-encoded so values beyond 2^53 survive JSON.
balanceUsdnumberSame balance, pre-divided for display.
updatedAtstringISO-8601 timestamp of the last ledger event.

speko.credits.getLedger(params?)

Most-recent-first page of credit movements (grants, debits, topups, refunds, adjustments). Pass the previous response’s nextCursor back as cursor to continue; null means the history is exhausted.

Signature

speko.credits.getLedger(
  params?: CreditLedgerQueryParams,
): Promise<CreditLedgerPage>

CreditLedgerQueryParams

FieldTypeDescription
limitnumber?Page size. Server default applies if omitted.
cursorstring?nextCursor from a previous response.

Returns — CreditLedgerPage

FieldTypeDescription
entriesCreditLedgerEntry[]Page contents.
nextCursorstring | nullPass back as cursor for the next page, null if done.

CreditLedgerEntry

FieldTypeDescription
idstringLedger entry id.
kind'grant' | 'debit' | 'topup' | 'refund' | 'adjustment'Movement type.
amountMicroUsdstringSigned. Positive for grants/topups/refunds, negative for debits.
metricstring | nullMetric when tied to a usage row.
providerstring | nullUpstream provider the debit was applied to.
sessionIdstring | nullSession the debit was applied against.
createdAtstringISO-8601.

Example — paginate the ledger

let cursor: string | undefined = undefined;

do {
  const page = await speko.credits.getLedger({ limit: 50, cursor });
  for (const entry of page.entries) {
    console.log(entry.createdAt, entry.kind, entry.amountMicroUsd);
  }
  cursor = page.nextCursor ?? undefined;
} while (cursor);