Module: RubyLLM::Agents::Pricing::LiteLLMAdapter

Extended by:
LiteLLMAdapter
Included in:
LiteLLMAdapter
Defined in:
lib/ruby_llm/agents/pricing/litellm_adapter.rb

Overview

Normalizes LiteLLM bulk JSON into the common pricing format.

Supports all model types:

  • Text LLM: input_cost_per_token, output_cost_per_token

  • Transcription: input_cost_per_second, input_cost_per_audio_token

  • TTS/Speech: input_cost_per_character, output_cost_per_character

  • Image: input_cost_per_image, input_cost_per_pixel

  • Embedding: input_cost_per_token (with mode: “embedding”)

Examples:

LiteLLMAdapter.find_model("whisper-1")
# => { input_cost_per_second: 0.0001, mode: "audio_transcription", source: :litellm }

Instance Method Summary collapse

Instance Method Details

#find_model(model_id) ⇒ Hash?

Find and normalize pricing for a model

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Hash, nil)

    Normalized pricing hash or nil



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

def find_model(model_id)
  data = DataStore.litellm_data
  return nil unless data.is_a?(Hash) && data.any?

  model_data = find_by_candidates(data, model_id)
  return nil unless model_data

  normalize(model_data)
end