Class: LlmCostTracker::Budget

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_cost_tracker/budget.rb

Class Method Summary collapse

Class Method Details

.check!(event) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/llm_cost_tracker/budget.rb', line 17

def check!(event)
  config = LlmCostTracker.configuration
  return unless event.cost

  check_per_call_budget(event, config)
  check_period_budget(event, config, :daily, config.daily_budget)
  check_period_budget(event, config, :monthly, config.monthly_budget)
end

.enforce!Object



8
9
10
11
12
13
14
15
# File 'lib/llm_cost_tracker/budget.rb', line 8

def enforce!
  config = LlmCostTracker.configuration
  return unless config.budget_exceeded_behavior == :block_requests
  return unless config.active_record?

  enforce_period_budget(:monthly, config.monthly_budget)
  enforce_period_budget(:daily, config.daily_budget)
end