Module: LlmCostTracker::Billing::CostStatus
- Defined in:
- lib/llm_cost_tracker/billing/cost_status.rb
Constant Summary collapse
- COMPLETE =
"complete"- FREE =
"free"- PARTIAL =
"partial"- UNKNOWN =
"unknown"
Class Method Summary collapse
-
.call(token_usage:, usage_source:, token_cost:, service_line_items:, total_cost:, token_pricing_partial: false) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
Class Method Details
.call(token_usage:, usage_source:, token_cost:, service_line_items:, total_cost:, token_pricing_partial: false) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/llm_cost_tracker/billing/cost_status.rb', line 15 def call(token_usage:, usage_source:, token_cost:, service_line_items:, total_cost:, token_pricing_partial: false) return UNKNOWN if usage_source == :unknown token_billable = Components::TOKEN_PRICED.any? do |component| token_usage.public_send(component.token_key).positive? end service_billable = false service_priced = false service_unpriced = false service_line_items.each do |line_item| next unless line_item.billable? service_billable = true service_priced ||= line_item.priced? service_unpriced ||= line_item.unpriced? break if service_priced && service_unpriced end priced = (token_billable && !token_cost.nil?) || service_priced || (!token_billable && !service_billable) unpriced = (token_billable && (token_cost.nil? || token_pricing_partial)) || service_unpriced return UNKNOWN if unpriced && !priced return PARTIAL if unpriced total_cost.nil? || total_cost.zero? ? FREE : COMPLETE end |