Class: RubyLLM::Providers::Moonshotai

Inherits:
OpenAI
  • Object
show all
Defined in:
app/lib/ruby_llm/providers/moonshotai.rb

Overview

Moonshot AI (Kimi) direct API — OpenAI-compatible endpoint.
Docs: https://platform.kimi.ai/docs/guide/kimi-k3-quickstart

RubyLLM 1.16 has no native Moonshot provider, so this shim subclasses the
OpenAI provider (Moonshot speaks the chat/completions dialect: tools,
streaming, json_schema response_format) and is registered as :moonshotai
— deliberately matching the models.dev / llm_models provider string so
the model registry, cost attribution (AiUsageLog), and
AiModelConstants.provider_for all agree on one name.

Context caching on Moonshot is fully automatic (stable prompt prefixes
are reused server-side with no cache IDs or params), so no provider-side
cache handling is needed. Remove this shim if ruby_llm ships a native
Moonshot provider.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configuration_optionsArray<Symbol>

Optional/required config keys registered on RubyLLM.config.

Returns:

  • (Array<Symbol>)


40
41
42
# File 'app/lib/ruby_llm/providers/moonshotai.rb', line 40

def configuration_options
  %i[moonshotai_api_key moonshotai_api_base]
end

.configuration_requirementsArray<Symbol>

Config keys that must be present before the provider can be used.

Returns:

  • (Array<Symbol>)


47
48
49
# File 'app/lib/ruby_llm/providers/moonshotai.rb', line 47

def configuration_requirements
  %i[moonshotai_api_key]
end

Instance Method Details

#api_baseString

API base URL for the international Moonshot endpoint.

Returns:

  • (String)


25
26
27
# File 'app/lib/ruby_llm/providers/moonshotai.rb', line 25

def api_base
  @config.moonshotai_api_base || 'https://api.moonshot.ai/v1'
end

#headersHash{String => String}

Bearer auth headers for the Moonshot API key.

Returns:

  • (Hash{String => String})


32
33
34
# File 'app/lib/ruby_llm/providers/moonshotai.rb', line 32

def headers
  { 'Authorization' => "Bearer #{@config.moonshotai_api_key}" }
end