Skip to content

Cost

Ledger sinks, summaries and resolved prices. Concepts: Cost.

Cost: the price table, the ledger, its sinks and summaries.

CallbackSink

Calls fn(entry) for every entry, e.g. to insert into a database.

JsonlSink

Appends one JSON line per entry (UTF-8), flushed and closed on every write.

LedgerPort

Bases: Protocol

Cost ledger; record is idempotent on (run_id, entry_id) and never raises.

run_id and thread_id filter together; neither means every entry.

LedgerSink

Bases: Protocol

Receives every entry the ledger records; may raise (the ledger logs and continues).

LedgerSummary

Bases: BaseModel

A run's (or every run's) cost, cache effectiveness and achieved parallelism.

MemorySink

Keeps every written entry, duplicates included, in entries.

ResolvedPrice dataclass

Token prices (USD per 1M tokens) for one model, tier and date.

StageSummary

Bases: BaseModel

Totals over one group of entries (a stage or a kind); unknown costs count as 0.

read_jsonl(path)

Entries from a JSON-lines file; the last line per (run_id, entry_id) wins.

A torn final line (a crash mid-write) is skipped with a WARNING.

Raises:

Type Description
ConfigError

the file cannot be read, or a line other than the last is invalid.

Also exported here, documented under the canonical path: Ledger, Prices.