agent-run-cost-rollup
Crystal command line tool and library. Give it a CSV of AI agent runs with their input and output token counts, plus the two prices you pay per one million tokens, and it rolls the cost up. Cost of a run = input_tokens / 1,000,000 * input price + output_tokens / 1,000,000 * output price. Per agent it prints runs, input tokens, output tokens, total cost, average cost per run (money with 4 decimals) and share of the total cost (1 decimal), sorted by total cost descending, then by agent name. It also prints the number of runs, the total cost and the most expensive single run (ties go to the alphabetically first run id). Both prices are required and are set by you: the tool has no price list, and the numbers 3 and 15 in the example are placeholders, not real prices. The token counts come from your own logs.
Part of the OneGTMLab free GTM tools. Background on the idea: AI agent.
Install
shards build # then ./bin/agent-run-cost-rollup
Use
Input: CSV with the columns run_id, agent, input_tokens and output_tokens (any order, header case does not matter). Tokens are whole numbers of 0 or more. Options: --input-price and --output-price, each a number of 0 or more, as --name value or --name=value. A missing price option, a negative or non-numeric token count (the message names the row, the header counts as row 1), a duplicate run_id, a missing column, a file with no rows or a missing file stops the run with a message and exit 1.
$ bin/agent-run-cost-rollup sample.csv --input-price 3 --output-price 15
agent runs input tokens output tokens total cost avg cost per run share of cost
Beta 2 15000 3000 0.0900 0.0450 65.2%
Alpha 3 4500 2100 0.0450 0.0150 32.6%
Gamma 1 500 100 0.0030 0.0030 2.2%
runs: 6
total cost: 0.1380
most expensive run: r3 (0.0600)
Test
crystal spec
Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.