module AgentRunCostRollup

Overview

Roll up the cost of AI agent runs from token counts. Prices are per one million tokens and are set by you; the tool has no price list.

Defined in:

agent_run_cost_rollup.cr

Constant Summary

REQUIRED = ["run_id", "agent", "input_tokens", "output_tokens"] of ::String
USAGE = "usage: agent-run-cost-rollup runs.csv --input-price P --output-price P\nCSV columns: run_id, agent, input_tokens, output_tokens. Prices are per one million tokens and are set by you (no defaults). More: https://www.onegtmlab.dev/glossary/ai-agent"
VERSION = "1.0.0"

Class Method Summary

Class Method Detail

def self.analyze(text : String, prices : Prices) : Report #

Parse the CSV text and build the report. Raises ArgumentError on bad input. Row numbers count the header as row 1.


[View source]
def self.cli(args : Array(String), stdout : IO, stderr : IO) : Int32 #

Command line entry. Returns the exit code: 0 ok, 1 bad input or file, 2 usage.


[View source]
def self.parse_csv(text : String) : Array(Array(String)) #

Small CSV reader: comma separated, double quoted fields may hold commas, line breaks and "" for a quote mark. Returns rows of raw cell strings.


[View source]
def self.render(report : Report) : String #

[View source]
def self.tokens(raw : String, field : String, n : Int32, id : String) : Int64 #

Parse a whole-number token cell. Raises ArgumentError naming the row.


[View source]