Module: RubyLLM::Agents::Pricing::LLMPricingAdapter
- Extended by:
- LLMPricingAdapter
- Included in:
- LLMPricingAdapter
- Defined in:
- lib/ruby_llm/agents/pricing/llmpricing_adapter.rb
Overview
Normalizes LLM Pricing AI per-model data into the common pricing format.
This API returns **calculated costs** for a given token count, not raw rates. We query with 1M tokens to derive per-token rates.
Coverage: ~79 models across 4 providers (OpenAI, Anthropic, Groq, Mistral). Text LLM only — no transcription, TTS, image, or embedding.
Constant Summary collapse
- PROVIDER_MAP =
[ [/^(gpt-|o1|o3|o4|whisper|dall-e|tts-|chatgpt)/, "OpenAI"], [/^claude/, "Anthropic"], [/^(mixtral|mistral|codestral|pixtral|ministral)/, "Mistral"], [/^(gemma|llama)/, "Groq"] ].freeze
- QUERY_TOKENS =
1_000_000
Instance Method Summary collapse
-
#find_model(model_id) ⇒ Hash?
Find and normalize pricing for a model.
Instance Method Details
#find_model(model_id) ⇒ Hash?
Find and normalize pricing for a model
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby_llm/agents/pricing/llmpricing_adapter.rb', line 34 def find_model(model_id) provider = resolve_provider(model_id) return nil unless provider raw = DataStore.llmpricing_data(provider, model_id, QUERY_TOKENS, QUERY_TOKENS) return nil unless raw.is_a?(Hash) return nil unless raw["input_cost"].is_a?(Numeric) && raw["input_cost"].positive? normalize(raw) end |