credits
Prepaid credit balance and append-only ledger.
Query the organization's prepaid credit balance and walk the ledger of every credit movement (grants, debits, topups, refunds, adjustments). Exposed via speko.credits.
Balances are returned in USD. Ledger amounts still use micro-USD strings because ledger entries are signed accounting units.
get_balance
Speko.credits.get_balance() -> OrganizationBalanceawait AsyncSpeko.credits.get_balance() -> OrganizationBalanceReturns the current balance for the caller's organization.
balance = speko.credits.get_balance()
if balance.balance_usd < 0.5:
print("Top up before running long sessions.")OrganizationBalance
balance_usdfloatcurrency'USD'updated_atstringISO-8601 timestamp of the last ledger event.
get_ledger
Speko.credits.get_ledger(
*,
limit: int | None = None,
cursor: str | None = None,
) -> CreditLedgerPageawait AsyncSpeko.credits.get_ledger(
*,
limit: int | None = None,
cursor: str | None = None,
) -> CreditLedgerPageMost-recent-first page of credit movements. Pass next_cursor from one response back in as cursor to fetch the next page; next_cursor is None means the history is exhausted.
page = speko.credits.get_ledger(limit=50)
while True:
for entry in page.entries:
print(entry.created_at, entry.kind, entry.amount_micro_usd, entry.provider)
if page.next_cursor is None:
break
page = speko.credits.get_ledger(limit=50, cursor=page.next_cursor)CreditLedgerEntry
idstringkind'grant' | 'debit' | 'topup' | 'refund' | 'adjustment'amount_micro_usdstringSigned — positive for grants/topups/refunds, negative for debits. String-encoded to survive JSON for values beyond 2^53.
metricstring | NoneBillable metric when the entry ties to a specific usage row.
providerstring | Nonesession_idstring | NoneSession the debit was applied against.
created_atstringCreditLedgerPage
entrieslist[CreditLedgerEntry]next_cursorstring | NoneCursor for the next page, or None when history is exhausted.