Module: RubyLLM::Agents::Pricing::PortkeyAdapter

Extended by:
PortkeyAdapter
Included in:
PortkeyAdapter
Defined in:
lib/ruby_llm/agents/pricing/portkey_adapter.rb

Overview

Normalizes Portkey AI per-model pricing into the common format.

Portkey prices are in **cents per token**. This adapter converts to USD per token for consistency with other adapters.

Requires knowing the provider for a model, resolved via PROVIDER_MAP.

Examples:

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

Constant Summary collapse

PROVIDER_MAP =
[
  [/^(gpt-|o1|o3|o4|whisper|dall-e|tts-|chatgpt)/, "openai"],
  [/^claude/, "anthropic"],
  [/^gemini/, "google"],
  [/^(mistral|codestral|pixtral|ministral)/, "mistralai"],
  [/^llama/, "meta"],
  [/^(command|embed)/, "cohere"],
  [/^deepseek/, "deepseek"],
  [/^(nova|titan)/, "amazon"]
].freeze

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



35
36
37
38
39
40
41
42
43
# File 'lib/ruby_llm/agents/pricing/portkey_adapter.rb', line 35

def find_model(model_id)
  provider, model_name = resolve_provider(model_id)
  return nil unless provider

  raw = DataStore.portkey_data(provider, model_name)
  return nil unless raw.is_a?(Hash) && raw["pay_as_you_go"]

  normalize(raw)
end