Skip to main content

rig_core/providers/
moonshot.rs

1//! Moonshot AI (Kimi) endpoints and model identifiers.
2//!
3//! [`from_env`] and [`new`] build a client on the
4//! [`MOONSHOT`](crate::providers::openai::wire::MOONSHOT) dialect, the module's
5//! primary one; [`anthropic_from_env`] and [`anthropic_new`] build a
6//! Messages-format client. Environment configuration reads `MOONSHOT_API_KEY`.
7//! `.responses(model)` speaks Moonshot's Responses endpoint, which serves the
8//! Kimi K3 family.
9//!
10//! ```no_run
11//! use rig_core::providers::moonshot;
12//!
13//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
14//! let kimi = moonshot::from_env()?.chat(moonshot::KIMI_K3);
15//! # let _ = kimi;
16//! # Ok(())
17//! # }
18//! ```
19
20/// Global OpenAI-compatible base URL.
21pub const GLOBAL_API_BASE_URL: &str = "https://api.moonshot.ai/v1";
22/// China OpenAI-compatible base URL.
23pub const CHINA_API_BASE_URL: &str = "https://api.moonshot.cn/v1";
24/// Anthropic-compatible base URL.
25pub const ANTHROPIC_API_BASE_URL: &str = "https://api.moonshot.ai/anthropic";
26/// China Anthropic-compatible base URL.
27pub const CHINA_ANTHROPIC_API_BASE_URL: &str = "https://api.moonshot.cn/anthropic";
28
29/// Identifier for the Kimi K3 model.
30pub const KIMI_K3: &str = "kimi-k3";
31
32/// Identifier for the Kimi K2.7 Code model.
33pub const KIMI_K2_7_CODE: &str = "kimi-k2.7-code";
34
35/// Identifier for the high-speed Kimi K2.7 Code model.
36pub const KIMI_K2_7_CODE_HIGHSPEED: &str = "kimi-k2.7-code-highspeed";
37
38/// Identifier for the Kimi K2.6 model.
39pub const KIMI_K2_6: &str = "kimi-k2.6";
40
41/// Whether Kimi `model` reads images: Kimi K2 before K2.5 and the
42/// `moonshot-v1` text models do not; K2.5 and later, and `*-vision-*`, do.
43/// Every wire Moonshot serves applies this rule to an id the catalog does
44/// not list.
45pub(crate) fn reads_images(model: &str) -> bool {
46    !(model == "kimi-k2"
47        || model.starts_with("kimi-k2-")
48        || (model.starts_with("moonshot-v1") && !model.contains("vision")))
49}
50
51pub mod extension;
52
53/// The provider key: the dialect name, a reply's `Origin::provider` and
54/// the typed provider-options key.
55pub const PROVIDER_NAME: &str = "moonshot";
56
57crate::client::macros::openai_vendor!(crate::providers::openai::wire::MOONSHOT, "Moonshot");
58crate::client::macros::anthropic_vendor!(
59    crate::providers::anthropic::wire::MOONSHOT,
60    "Moonshot",
61    anthropic_from_env,
62    anthropic_new
63);
64
65#[cfg(test)]
66mod tests;