Module: RubyLLM::Agents::Audio::TranscriptionPricing

Extended by:
TranscriptionPricing
Included in:
TranscriptionPricing
Defined in:
lib/ruby_llm/agents/audio/transcription_pricing.rb

Overview

Dynamic pricing resolution for audio transcription models.

Cascades through multiple pricing sources to maximize coverage:

  1. User config (instant, always wins)

  2. RubyLLM gem (local, no HTTP, already a dependency)

  3. LiteLLM (bulk, most comprehensive for transcription)

  4. Portkey AI (per-model, good transcription coverage)

  5. OpenRouter (bulk, audio-capable chat models only)

  6. Helicone (text LLM only — pass-through, future-proof)

  7. LLM Pricing AI (text LLM only — pass-through, future-proof)

When no pricing is found, methods return nil to signal the caller should warn the user with actionable configuration instructions.

All prices are per minute of audio.

Examples:

Get cost for a transcription

TranscriptionPricing.calculate_cost(model_id: "whisper-1", duration_seconds: 120)
# => 0.012 (or nil if no pricing found)

User-configured pricing

RubyLLM::Agents.configure do |c|
  c.transcription_model_pricing = { "whisper-1" => 0.006 }
end

Constant Summary collapse

SOURCES =
[:config, :ruby_llm, :litellm, :portkey, :openrouter, :helicone, :llmpricing].freeze

Instance Method Summary collapse

Instance Method Details

#all_pricingHash

Expose all known pricing for debugging/console inspection

Returns:

  • (Hash)

    Pricing from all tiers



85
86
87
88
89
90
91
92
93
94
# File 'lib/ruby_llm/agents/audio/transcription_pricing.rb', line 85

def all_pricing
  {
    ruby_llm: {},
    litellm: litellm_transcription_models,
    portkey: {},
    openrouter: {},
    helicone: {},
    configured: config.transcription_model_pricing || {}
  }
end

#calculate_cost(model_id:, duration_seconds:) ⇒ Float?

Calculate total cost for a transcription operation

Parameters:

  • model_id (String)

    The model identifier

  • duration_seconds (Numeric)

    Duration of audio in seconds

Returns:

  • (Float, nil)

    Total cost in USD, or nil if no pricing found



49
50
51
52
53
54
55
# File 'lib/ruby_llm/agents/audio/transcription_pricing.rb', line 49

def calculate_cost(model_id:, duration_seconds:)
  price = cost_per_minute(model_id)
  return nil unless price

  duration_minutes = duration_seconds / 60.0
  (duration_minutes * price).round(6)
end

#cost_per_minute(model_id) ⇒ Float?

Get cost per minute for a transcription model

Parameters:

  • model_id (String)

    Model identifier

Returns:

  • (Float, nil)

    Cost per minute in USD, or nil if not found



61
62
63
64
65
66
67
# File 'lib/ruby_llm/agents/audio/transcription_pricing.rb', line 61

def cost_per_minute(model_id)
  SOURCES.each do |source|
    price = send(:"from_#{source}", model_id)
    return price if price
  end
  nil
end

#pricing_found?(model_id) ⇒ Boolean

Check whether pricing is available for a model

Parameters:

  • model_id (String)

    Model identifier

Returns:

  • (Boolean)

    true if pricing is available



73
74
75
# File 'lib/ruby_llm/agents/audio/transcription_pricing.rb', line 73

def pricing_found?(model_id)
  !cost_per_minute(model_id).nil?
end

#refresh!Object

Force refresh of cached pricing data



78
79
80
# File 'lib/ruby_llm/agents/audio/transcription_pricing.rb', line 78

def refresh!
  Pricing::DataStore.refresh!
end