Speko Docs

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() -> OrganizationBalance
await AsyncSpeko.credits.get_balance() -> OrganizationBalance

Returns 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_usdfloat
currency'USD'
updated_atstring

ISO-8601 timestamp of the last ledger event.

get_ledger

Speko.credits.get_ledger(
    *,
    limit: int | None = None,
    cursor: str | None = None,
) -> CreditLedgerPage
await AsyncSpeko.credits.get_ledger(
    *,
    limit: int | None = None,
    cursor: str | None = None,
) -> CreditLedgerPage

Most-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

idstring
kind'grant' | 'debit' | 'topup' | 'refund' | 'adjustment'
amount_micro_usdstring

Signed — positive for grants/topups/refunds, negative for debits. String-encoded to survive JSON for values beyond 2^53.

metricstring | None

Billable metric when the entry ties to a specific usage row.

providerstring | None
session_idstring | None

Session the debit was applied against.

created_atstring

CreditLedgerPage

entrieslist[CreditLedgerEntry]
next_cursorstring | None

Cursor for the next page, or None when history is exhausted.

On this page