Module: RubyLLM::Agents::Audio::ElevenLabs::ModelRegistry

Extended by:
ModelRegistry
Included in:
ModelRegistry
Defined in:
lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb

Overview

Fetches and caches ElevenLabs model data from the /v1/models API.

Used for:

  • Dynamic cost calculation via character_cost_multiplier

  • Model validation (TTS vs STS capability)

  • Capability awareness (style, speaker_boost, max chars, languages)

Examples:

Check if a model supports TTS

ElevenLabs::ModelRegistry.tts_model?("eleven_v3") # => true
ElevenLabs::ModelRegistry.tts_model?("eleven_english_sts_v2") # => false

Get cost multiplier

ElevenLabs::ModelRegistry.cost_multiplier("eleven_flash_v2_5") # => 0.5

Instance Method Summary collapse

Instance Method Details

#clear_cache!void

This method returns an undefined value.

Clear cache without re-fetching (useful for tests)



132
133
134
135
136
137
138
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 132

def clear_cache!
  @mutex ||= Mutex.new
  @mutex.synchronize do
    @models = nil
    @fetched_at = nil
  end
end

#cost_multiplier(model_id) ⇒ Float

Get character_cost_multiplier for a model

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Float)

    Cost multiplier (defaults to 1.0 for unknown models)



66
67
68
69
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 66

def cost_multiplier(model_id)
  model = find(model_id)
  model&.dig("model_rates", "character_cost_multiplier") || 1.0
end

#find(model_id) ⇒ Hash?

Find a specific model by ID

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Hash, nil)

    Model hash or nil if not found



47
48
49
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 47

def find(model_id)
  models.find { |m| m["model_id"] == model_id.to_s }
end

#languages(model_id) ⇒ Array<String>

Get supported language IDs for a model

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Array<String>)

    Language IDs (e.g. [“en”, “es”, “ja”])



84
85
86
87
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 84

def languages(model_id)
  model = find(model_id)
  model&.dig("languages")&.map { |l| l["language_id"] } || []
end

#max_characters(model_id) ⇒ Integer?

Get max characters per request for a model

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Integer, nil)

    Max characters or nil if unknown



75
76
77
78
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 75

def max_characters(model_id)
  model = find(model_id)
  model&.dig("maximum_text_length_per_request")
end

#modelsArray<Hash>

Returns all models from the ElevenLabs API (cached)

Returns:

  • (Array<Hash>)

    Array of model hashes



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 30

def models
  @mutex ||= Mutex.new
  @mutex.synchronize do
    if @models && !cache_expired?
      return @models
    end

    @models = fetch_models
    @fetched_at = Time.now
    @models
  end
end

#refresh!Array<Hash>

Force refresh the cache

Returns:

  • (Array<Hash>)

    Fresh model data



120
121
122
123
124
125
126
127
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 120

def refresh!
  @mutex ||= Mutex.new
  @mutex.synchronize do
    @models = nil
    @fetched_at = nil
  end
  models
end

#supports_speaker_boost?(model_id) ⇒ Boolean

Check if model supports the speaker_boost setting

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Boolean)


101
102
103
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 101

def supports_speaker_boost?(model_id)
  find(model_id)&.dig("can_use_speaker_boost") == true
end

#supports_style?(model_id) ⇒ Boolean

Check if model supports the style voice setting

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Boolean)


93
94
95
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 93

def supports_style?(model_id)
  find(model_id)&.dig("can_use_style") == true
end

#tts_model?(model_id) ⇒ Boolean

Check if model supports text-to-speech

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 55

def tts_model?(model_id)
  model = find(model_id)
  return false unless model

  model["can_do_text_to_speech"] == true
end

#voice_conversion_model?(model_id) ⇒ Boolean

Check if model supports voice conversion (speech-to-speech) Used by VoiceConverter agent (see plans/elevenlabs_voice_converter.md)

Parameters:

  • model_id (String)

    The model identifier

Returns:

  • (Boolean)


110
111
112
113
114
115
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 110

def voice_conversion_model?(model_id)
  model = find(model_id)
  return false unless model

  model["can_do_voice_conversion"] == true
end