Module: RubyLLM::Agents::Audio::SpeechPricing
- Extended by:
- SpeechPricing
- Included in:
- SpeechPricing
- Defined in:
- lib/ruby_llm/agents/audio/speech_pricing.rb
Overview
Dynamic pricing resolution for text-to-speech models.
Uses a three-tier pricing cascade (no hardcoded prices):
-
Configurable pricing table - user overrides via config.tts_model_pricing
-
LiteLLM (via shared DataStore) - comprehensive, community-maintained
-
ElevenLabs API - dynamic multiplier × user-configured base rate
When no pricing is found, returns 0 to signal unknown cost.
All prices are per 1,000 characters.
Instance Method Summary collapse
-
#all_pricing ⇒ Object
Expose all known pricing for debugging/console inspection.
-
#calculate_cost(provider:, model_id:, characters:) ⇒ Float
Calculate total cost for a speech operation.
-
#cost_per_1k_characters(provider, model_id) ⇒ Float
Get cost per 1,000 characters for a model.
-
#refresh! ⇒ Object
Force refresh of cached pricing data.
Instance Method Details
#all_pricing ⇒ Object
Expose all known pricing for debugging/console inspection
78 79 80 81 82 83 84 |
# File 'lib/ruby_llm/agents/audio/speech_pricing.rb', line 78 def all_pricing { litellm: litellm_tts_models, configured: config.tts_model_pricing || {}, elevenlabs_api: elevenlabs_api_pricing } end |
#calculate_cost(provider:, model_id:, characters:) ⇒ Float
Calculate total cost for a speech operation
42 43 44 45 |
# File 'lib/ruby_llm/agents/audio/speech_pricing.rb', line 42 def calculate_cost(provider:, model_id:, characters:) price_per_1k = cost_per_1k_characters(provider, model_id) ((characters / 1000.0) * price_per_1k).round(6) end |
#cost_per_1k_characters(provider, model_id) ⇒ Float
Get cost per 1,000 characters for a model
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby_llm/agents/audio/speech_pricing.rb', line 52 def cost_per_1k_characters(provider, model_id) # Tier 1: User config overrides (highest priority) if (config_price = from_config(model_id)) return config_price end # Tier 2: LiteLLM (via shared adapter/DataStore) if (litellm_price = from_litellm(model_id)) return litellm_price end # Tier 3: ElevenLabs API multiplier × user-configured base rate if provider == :elevenlabs && (api_price = from_elevenlabs_api(model_id)) return api_price end # No pricing found — return user-configured default or 0 config.default_tts_cost || 0 end |