Module: Clacky::Providers

Defined in:
lib/clacky/providers.rb

Overview

Built-in model provider presets Provides default configurations for supported AI model providers

Constant Summary collapse

PRESETS =

Provider preset definitions Each preset includes:

  • name: Human-readable provider name

  • base_url: Default API endpoint

  • api: API type (anthropic-messages, openai-responses, openai-completions)

  • default_model: Recommended default model

{

  "openrouter" => {
    "name" => "OpenRouter",
    "base_url" => "https://openrouter.ai/api/v1",
    "api" => "openai-responses",
    "default_model" => "anthropic/claude-sonnet-4-6",
    "lite_model" => "anthropic/claude-haiku-4-5",
    "models" => [],  # Dynamic - fetched from API
    "website_url" => "https://openrouter.ai/keys"
  }.freeze,

  "minimax" => {
    "name" => "Minimax",
    "base_url" => "https://api.minimaxi.com/v1",
    "api" => "openai-completions",
    "default_model" => "MiniMax-M2.7",
    "models" => ["MiniMax-M2.5", "MiniMax-M2.7"],
    "website_url" => "https://www.minimaxi.com/user-center/basic-information/interface-key"
  }.freeze,

  "kimi" => {
    "name" => "Kimi (Moonshot)",
    "base_url" => "https://api.moonshot.cn/v1",
    "api" => "openai-completions",
    "default_model" => "kimi-k2.5",
    "models" => ["kimi-k2.5"],
    "website_url" => "https://platform.moonshot.cn/console/api-keys"
  }.freeze,

  "anthropic" => {
    "name" => "Anthropic (Claude)",
    "base_url" => "https://api.anthropic.com",
    "api" => "anthropic-messages",
    "default_model" => "claude-sonnet-4.6",
    "models" => ["claude-opus-4-6", "claude-sonnet-4.6", "claude-haiku-4.5"],
    "website_url" => "https://console.anthropic.com/settings/keys"
  }.freeze,

  "clackyai" => {
    "name" => "ClackyAI",
    "base_url" => "https://api.clacky.ai",
    "api" => "bedrock",
    "default_model" => "abs-claude-sonnet-4-6",
    "lite_model" => "abs-claude-haiku-4-5",
    "models" => [
      "abs-claude-opus-4-6",
      "abs-claude-sonnet-4-6",
      "abs-claude-haiku-4-5"
    ],
    # Fallback chain: if a model is unavailable, try the next one in order.
    # Keys are primary model names; values are the fallback model to use instead.
    "fallback_models" => {
      "abs-claude-sonnet-4-6" => "abs-claude-sonnet-4-5"
    },
    "website_url" => "https://clacky.ai"
  }.freeze,

  "mimo" => {
    "name" => "MiMo (Xiaomi)",
    "base_url" => "https://api.xiaomimimo.com/v1",
    "api" => "openai-completions",
    "default_model" => "mimo-v2-pro",
    "models" => ["mimo-v2-pro", "mimo-v2-omni"],
    "website_url" => "https://platform.xiaomimimo.com/"
  }.freeze

}.freeze

Class Method Summary collapse

Class Method Details

.api_type(provider_id) ⇒ String?

Get the API type for a provider

Parameters:

  • provider_id (String)

    The provider identifier

Returns:

  • (String, nil)

    The API type or nil if provider not found



116
117
118
119
# File 'lib/clacky/providers.rb', line 116

def api_type(provider_id)
  preset = PRESETS[provider_id]
  preset&.dig("api")
end

.base_url(provider_id) ⇒ String?

Get the base URL for a provider

Parameters:

  • provider_id (String)

    The provider identifier

Returns:

  • (String, nil)

    The base URL or nil if provider not found



108
109
110
111
# File 'lib/clacky/providers.rb', line 108

def base_url(provider_id)
  preset = PRESETS[provider_id]
  preset&.dig("base_url")
end

.default_model(provider_id) ⇒ String?

Get the default model for a provider

Parameters:

  • provider_id (String)

    The provider identifier

Returns:

  • (String, nil)

    The default model name or nil if provider not found



100
101
102
103
# File 'lib/clacky/providers.rb', line 100

def default_model(provider_id)
  preset = PRESETS[provider_id]
  preset&.dig("default_model")
end

.exists?(provider_id) ⇒ Boolean

Check if a provider preset exists

Parameters:

  • provider_id (String)

    The provider identifier (e.g., “anthropic”, “openrouter”)

Returns:

  • (Boolean)

    True if the preset exists



86
87
88
# File 'lib/clacky/providers.rb', line 86

def exists?(provider_id)
  PRESETS.key?(provider_id)
end

.fallback_model(provider_id, model) ⇒ String?

Get the fallback model for a given model within a provider. Returns nil if no fallback is defined for that model.

Parameters:

  • provider_id (String)

    The provider identifier

  • model (String)

    The primary model name

Returns:

  • (String, nil)

    The fallback model name or nil



154
155
156
157
# File 'lib/clacky/providers.rb', line 154

def fallback_model(provider_id, model)
  preset = PRESETS[provider_id]
  preset&.dig("fallback_models", model)
end

.find_by_base_url(base_url) ⇒ String?

Find provider ID by base URL. Matches if the given URL starts with the provider’s base_url (after normalisation), so both exact matches and sub-path variants (e.g. “/v1”) are recognised.

Parameters:

  • base_url (String)

    The base URL to look up

Returns:

  • (String, nil)

    The provider ID or nil if not found



164
165
166
167
168
169
170
171
# File 'lib/clacky/providers.rb', line 164

def find_by_base_url(base_url)
  return nil if base_url.nil? || base_url.empty?
  normalized = base_url.to_s.chomp("/")
  PRESETS.find do |_id, preset|
    preset_base = preset["base_url"].to_s.chomp("/")
    normalized == preset_base || normalized.start_with?("#{preset_base}/")
  end&.first
end

.get(provider_id) ⇒ Hash?

Get a provider preset by ID

Parameters:

  • provider_id (String)

    The provider identifier

Returns:

  • (Hash, nil)

    The preset configuration or nil if not found



93
94
95
# File 'lib/clacky/providers.rb', line 93

def get(provider_id)
  PRESETS[provider_id]
end

.listArray<Array(String, String)>

List all available providers with their names

Returns:

  • (Array<Array(String, String)>)

    Array of [id, name] pairs



129
130
131
# File 'lib/clacky/providers.rb', line 129

def list
  PRESETS.map { |id, config| [id, config["name"]] }
end

.lite_model(provider_id) ⇒ String?

Get the lite model for a provider (if any)

Parameters:

  • provider_id (String)

    The provider identifier

Returns:

  • (String, nil)

    The lite model name or nil if provider has no lite model



144
145
146
147
# File 'lib/clacky/providers.rb', line 144

def lite_model(provider_id)
  preset = PRESETS[provider_id]
  preset&.dig("lite_model")
end

.models(provider_id) ⇒ Array<String>

Get available models for a provider

Parameters:

  • provider_id (String)

    The provider identifier

Returns:

  • (Array<String>)

    List of model names (empty if dynamic)



136
137
138
139
# File 'lib/clacky/providers.rb', line 136

def models(provider_id)
  preset = PRESETS[provider_id]
  preset&.dig("models") || []
end

.provider_idsArray<String>

List all available provider IDs

Returns:

  • (Array<String>)

    List of provider identifiers



123
124
125
# File 'lib/clacky/providers.rb', line 123

def provider_ids
  PRESETS.keys
end