Module: RubyLLM::Agents::Pricing::RubyLLMAdapter

Extended by:
RubyLLMAdapter
Included in:
RubyLLMAdapter
Defined in:
lib/ruby_llm/agents/pricing/ruby_llm_adapter.rb

Overview

Extracts pricing from the ruby_llm gem’s built-in model registry.

This is a local, zero-HTTP-cost source that provides pricing for models that ruby_llm knows about. It’s the fastest adapter since all data is already loaded in-process.

Uses RubyLLM::Models.find(model_id) which returns pricing as USD per million tokens.

Examples:

RubyLLMAdapter.find_model("gpt-4o")
# => { input_cost_per_token: 0.0000025, output_cost_per_token: 0.00001, source: :ruby_llm }

Instance Method Summary collapse

Instance Method Details

#find_model(model_id) ⇒ Hash?

Find and normalize pricing for a model from ruby_llm’s registry

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Hash, nil)

    Normalized pricing hash or nil



26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_llm/agents/pricing/ruby_llm_adapter.rb', line 26

def find_model(model_id)
  return nil unless defined?(::RubyLLM::Models)

  model_info = ::RubyLLM::Models.find(model_id)
  return nil unless model_info

  normalize(model_info)
rescue
  nil
end