Skip to main content
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 micro-USD (1_000_000 µ$ = $1). The SDK also pre-divides to float USD for display.

get_balance

Speko.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_micro_usd
string
Current balance in micro-USD, as string for lossless round-trips.
balance_usd
float
updated_at
string
ISO-8601 timestamp of the last ledger event.

get_ledger

Speko.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

id
string
kind
'grant' | 'debit' | 'topup' | 'refund' | 'adjustment'
amount_micro_usd
string
Signed — positive for grants/topups/refunds, negative for debits. String-encoded to survive JSON for values beyond 2^53.
metric
string | None
Billable metric when the entry ties to a specific usage row.
provider
string | None
session_id
string | None
Session the debit was applied against.
created_at
string

CreditLedgerPage

entries
list[CreditLedgerEntry]
next_cursor
string | None
Cursor for the next page, or None when history is exhausted.