Class: Ace::Support::Models::Models::PricingInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/models/models/pricing_info.rb

Overview

Represents pricing information for a model (per million tokens)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input: nil, output: nil, reasoning: nil, cache_read: nil, cache_write: nil) ⇒ PricingInfo

Initialize pricing info

Parameters:

  • input (Float, nil) (defaults to: nil)

    Input cost per million tokens

  • output (Float, nil) (defaults to: nil)

    Output cost per million tokens

  • reasoning (Float, nil) (defaults to: nil)

    Reasoning cost per million tokens

  • cache_read (Float, nil) (defaults to: nil)

    Cache read cost per million tokens

  • cache_write (Float, nil) (defaults to: nil)

    Cache write cost per million tokens



17
18
19
20
21
22
23
# File 'lib/ace/support/models/models/pricing_info.rb', line 17

def initialize(input: nil, output: nil, reasoning: nil, cache_read: nil, cache_write: nil)
  @input = input
  @output = output
  @reasoning = reasoning
  @cache_read = cache_read
  @cache_write = cache_write
end

Instance Attribute Details

#cache_readObject (readonly)

Returns the value of attribute cache_read.



9
10
11
# File 'lib/ace/support/models/models/pricing_info.rb', line 9

def cache_read
  @cache_read
end

#cache_writeObject (readonly)

Returns the value of attribute cache_write.



9
10
11
# File 'lib/ace/support/models/models/pricing_info.rb', line 9

def cache_write
  @cache_write
end

#inputObject (readonly)

Returns the value of attribute input.



9
10
11
# File 'lib/ace/support/models/models/pricing_info.rb', line 9

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



9
10
11
# File 'lib/ace/support/models/models/pricing_info.rb', line 9

def output
  @output
end

#reasoningObject (readonly)

Returns the value of attribute reasoning.



9
10
11
# File 'lib/ace/support/models/models/pricing_info.rb', line 9

def reasoning
  @reasoning
end

Class Method Details

.from_hash(hash) ⇒ PricingInfo

Create from API hash

Parameters:

  • hash (Hash)

    Cost hash from API

Returns:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ace/support/models/models/pricing_info.rb', line 28

def self.from_hash(hash)
  return new if hash.nil?

  new(
    input: hash["input"],
    output: hash["output"],
    reasoning: hash["reasoning"],
    cache_read: hash["cache_read"],
    cache_write: hash["cache_write"]
  )
end

Instance Method Details

#available?Boolean

Check if pricing data is available

Returns:

  • (Boolean)

    true if any pricing data exists



54
55
56
# File 'lib/ace/support/models/models/pricing_info.rb', line 54

def available?
  input || output
end

#calculate(input_tokens:, output_tokens:, reasoning_tokens: 0) ⇒ Float

Calculate total cost for token counts

Parameters:

  • input_tokens (Integer)

    Input token count

  • output_tokens (Integer)

    Output token count

  • reasoning_tokens (Integer) (defaults to: 0)

    Reasoning token count

Returns:

  • (Float)

    Total cost in dollars



63
64
65
66
67
68
69
# File 'lib/ace/support/models/models/pricing_info.rb', line 63

def calculate(input_tokens:, output_tokens:, reasoning_tokens: 0)
  total = 0.0
  total += (input_tokens / 1_000_000.0) * input if input
  total += (output_tokens / 1_000_000.0) * output if output
  total += (reasoning_tokens / 1_000_000.0) * reasoning if reasoning && reasoning_tokens > 0
  total
end

#to_hHash

Convert to hash

Returns:

  • (Hash)

    Pricing as hash



42
43
44
45
46
47
48
49
50
# File 'lib/ace/support/models/models/pricing_info.rb', line 42

def to_h
  {
    input: input,
    output: output,
    reasoning: reasoning,
    cache_read: cache_read,
    cache_write: cache_write
  }.compact
end