class Riffer::Config::Pricing::Rates
Per-million-token rates for one modelβs four token buckets. cache_read and cache_write fall back to the input rate when unset.
Attributes
Cache-read rate per million tokens.
Cache-write rate per million tokens.
Input rate per million tokens.
Output rate per million tokens.
Public Class Methods
Source
# File lib/riffer/config.rb, line 172 def initialize(input:, output:, cache_read: nil, cache_write: nil) @input = input @output = output @cache_read = cache_read @cache_write = cache_write end
Public Instance Methods
Source
# File lib/riffer/config.rb, line 182 def cost_for(input_tokens:, output_tokens:, cache_read_tokens: nil, cache_write_tokens: nil) read = cache_read_tokens || 0 write = cache_write_tokens || 0 uncached = input_tokens - read - write uncached = 0 if uncached.negative? per_million = uncached * input + read * (cache_read || input) + write * (cache_write || input) + output_tokens * output per_million / 1_000_000.0 end
Returns the cost for the given token counts.