Class: RubyLLM::Providers::Moonshotai
- Inherits:
-
OpenAI
- Object
- OpenAI
- RubyLLM::Providers::Moonshotai
- 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
-
.configuration_options ⇒ Array<Symbol>
Optional/required config keys registered on RubyLLM.config.
-
.configuration_requirements ⇒ Array<Symbol>
Config keys that must be present before the provider can be used.
Instance Method Summary collapse
-
#api_base ⇒ String
API base URL for the international Moonshot endpoint.
-
#headers ⇒ Hash{String => String}
Bearer auth headers for the Moonshot API key.
Class Method Details
.configuration_options ⇒ Array<Symbol>
Optional/required config keys registered on RubyLLM.config.
40 41 42 |
# File 'app/lib/ruby_llm/providers/moonshotai.rb', line 40 def %i[moonshotai_api_key moonshotai_api_base] end |
.configuration_requirements ⇒ Array<Symbol>
Config keys that must be present before the provider can be used.
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_base ⇒ String
API base URL for the international Moonshot endpoint.
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 |
#headers ⇒ Hash{String => String}
Bearer auth headers for the Moonshot API key.
32 33 34 |
# File 'app/lib/ruby_llm/providers/moonshotai.rb', line 32 def headers { 'Authorization' => "Bearer #{@config.moonshotai_api_key}" } end |