Module: RubyLLM::Agents::Pricing::OpenRouterAdapter

Extended by:
OpenRouterAdapter
Included in:
OpenRouterAdapter
Defined in:
lib/ruby_llm/agents/pricing/openrouter_adapter.rb

Overview

Normalizes OpenRouter bulk model list into the common pricing format.

OpenRouter prices are strings representing USD per token. This adapter converts them to Float.

Coverage: 400+ text LLM models, some audio-capable chat models. No transcription, image generation, or embedding models.

Examples:

OpenRouterAdapter.find_model("openai/gpt-4o")
# => { input_cost_per_token: 0.0000025, output_cost_per_token: 0.00001, source: :openrouter }

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



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

def find_model(model_id)
  models = DataStore.openrouter_data
  return nil unless models.is_a?(Array) && models.any?

  entry = find_by_id(models, model_id)
  return nil unless entry

  normalize(entry)
end