module

MJ::Spend

Cost ledger for paid API calls. Runware reports a per-task cost (USD) when a task asks for it with includeCost; every billed call is tallied for the run and appended as one JSONL row to a persistent ledger, so spend is visible per-call, per-run and over time (mj spend).

ledger $MJ_SPEND_LOG, else $XDG_DATA_HOME/mj/spend.jsonl off MJ_SPEND_LOG=0 — no ledger row is written (the run tally still prints)

A row: {"t","cmd","provider","task","model","cost","w","h"} — cost may be null if the provider returned none (never silently counted as free; see unpriced).

Instance methods

command

The mj subcommand this process is running, for attribution in the ledger.

Source
entries

Every ledger row, oldest first. Unparseable lines are skipped, not fatal.

Source
install_summary!

Print the run tally once, on exit. Armed lazily by the first recorded call.

Source
ledger_path
Source
logging?
Source
money(v : Float64) : String
Source
record(task : String, model : String, cost : Float64 | Nil, width : Int32 | Nil = nil, height : Int32 | Nil = nil, provider : String = "runware") : Nil

Record one billed call. cost nil = the provider reported none.

Source
report(io : IO = STDOUT, since : Time | Nil = nil) : Nil

Human summary of the ledger since since (nil = everything): a per-day table, then breakdowns by model and by command.

Source
report_json(io : IO = STDOUT, since : Time | Nil = nil) : Nil

JSON form of the same window, for scripts.

Source
session_calls
Source
session_cost
Source
session_unpriced
Source
total(rows : Array(Entry)) : Float64
Source

Nested types