Class: AgentC::Costs::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_c/costs/report.rb

Defined Under Namespace

Classes: Calculator, Printer

Constant Summary collapse

PRICING =

Anthropic models Price per 1,000 input tokens Price per 1,000 output tokens Price per 1,000 input tokens (batch) Price per 1,000 output tokens (batch) Price per 1,000 input tokens (5m cache write) Price per 1,000 input tokens (1h cache write) Price per 1,000 input tokens (cache read) Claude Sonnet 4.5 $0.003 $0.015 $0.0015 $0.0075 $0.00375 $0.006 $0.0003 Claude Sonnet 4.5 - Long Context $0.006 $0.0225 $0.003 $0.01125 $0.0075 $0.012 $0.0006

{
  normal: {
    input: 3.0,              # $0.003 per 1k tokens
    output: 15.0,            # $0.015 per 1k tokens
    cached_input: 0.3,       # $0.0003 per 1k tokens (cache read)
    cache_creation: 3.75     # $0.00375 per 1k tokens (5m cache write)
  },
  long: {
    input: 6.0,              # $0.006 per 1k tokens
    output: 22.5,            # $0.0225 per 1k tokens
    cached_input: 0.6,       # $0.0006 per 1k tokens (cache read)
    cache_creation: 7.5      # $0.0075 per 1k tokens (5m cache write)
  }
}.freeze
LONG_CONTEXT_THRESHOLD =

tokens

200_000

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_store:, project: nil, run_id: nil, out: $stdout) ⇒ Report

Returns a new instance of Report.



32
33
34
35
36
37
38
39
# File 'lib/agent_c/costs/report.rb', line 32

def initialize(agent_store:, project: nil, run_id: nil, out: $stdout)
  @agent_store = agent_store
  @project = project
  @run_id = run_id
  @out = out
  @calculator = Calculator.new
  @printer = Printer.new(out: @out)
end

Class Method Details

.callObject



28
29
30
# File 'lib/agent_c/costs/report.rb', line 28

def self.call(...)
  new(...).call
end

Instance Method Details

#callObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/agent_c/costs/report.rb', line 41

def call
  # Gather all computations based on hierarchy
  computations = []

  # Always compute totals for all projects
  all_messages = fetch_all_messages
  if all_messages.any?
    computations << {
      label: "All Projects",
      stats: @calculator.calculate(all_messages),
      messages: all_messages
    }
  end

  # If project is specified, add project-level computation
  if @project
    project_messages = fetch_project_messages
    if project_messages.any?
      computations << {
        label: "Project: #{@project}",
        stats: @calculator.calculate(project_messages),
        messages: project_messages
      }
    end

    # If run_id is also specified, add run-level computation
    if @run_id
      run_messages = fetch_run_messages
      if run_messages.any?
        computations << {
          label: "Project: #{@project}, Run ID: #{@run_id}",
          stats: @calculator.calculate(run_messages),
          messages: run_messages
        }
      end
    end
  end

  if computations.empty?
    @out.puts "No messages found" if @out
    return []
  end

  # Print to output if provided
  if @out
    @printer.print_hierarchical_report(computations)
  end

  # Return structured data
  computations
end