Class: PromptObjects::LLM::Pricing
- Inherits:
-
Object
- Object
- PromptObjects::LLM::Pricing
- Defined in:
- lib/prompt_objects/llm/pricing.rb
Overview
Static pricing table for cost estimation. Prices are per 1 million tokens in USD. Updated periodically — not guaranteed to be exact.
Constant Summary collapse
- RATES =
{ # OpenAI "gpt-5.6-sol" => { input: 5.00, output: 30.00 }, "gpt-5.6-terra" => { input: 2.50, output: 15.00 }, "gpt-5.6-luna" => { input: 1.00, output: 6.00 }, "gpt-5.4-mini" => { input: 0.75, output: 4.50 }, "gpt-5.4-nano" => { input: 0.20, output: 1.25 }, "gpt-5.2" => { input: 2.00, output: 8.00 }, "gpt-4.1" => { input: 2.00, output: 8.00 }, "gpt-4.1-mini" => { input: 0.40, output: 1.60 }, "gpt-4.5-preview" => { input: 75.00, output: 150.00 }, "o3-mini" => { input: 1.10, output: 4.40 }, "o1" => { input: 15.00, output: 60.00 }, # Anthropic "claude-opus-4" => { input: 15.00, output: 75.00 }, "claude-sonnet-4-5" => { input: 3.00, output: 15.00 }, "claude-haiku-4-5" => { input: 1.00, output: 5.00 }, # Gemini "gemini-3.5-flash" => { input: 1.50, output: 9.00 }, "gemini-3.1-flash-lite" => { input: 0.25, output: 1.50 }, "gemini-3-flash-preview" => { input: 0.50, output: 3.00 }, "gemini-2.5-pro" => { input: 1.25, output: 10.00 }, "gemini-2.5-flash" => { input: 0.30, output: 2.50 }, }.freeze
Class Method Summary collapse
-
.calculate(model:, input_tokens:, output_tokens:) ⇒ Float
Calculate cost in USD for a given usage.
-
.known_model?(model) ⇒ Boolean
Check if we have pricing data for a model.
Class Method Details
.calculate(model:, input_tokens:, output_tokens:) ⇒ Float
Calculate cost in USD for a given usage.
39 40 41 42 43 44 45 46 |
# File 'lib/prompt_objects/llm/pricing.rb', line 39 def self.calculate(model:, input_tokens:, output_tokens:) rates = RATES[model] return 0.0 unless rates input_cost = (input_tokens / 1_000_000.0) * rates[:input] output_cost = (output_tokens / 1_000_000.0) * rates[:output] input_cost + output_cost end |
.known_model?(model) ⇒ Boolean
Check if we have pricing data for a model.
51 52 53 |
# File 'lib/prompt_objects/llm/pricing.rb', line 51 def self.known_model?(model) RATES.key?(model) end |