rig_core/providers/zai.rs
1//! Z.AI's endpoints and model identifiers.
2//!
3//! [`from_env`] and [`new`] build a client on the chat-completions
4//! [`ZAI`](crate::providers::openai::wire::ZAI) dialect, the module's primary
5//! one; [`anthropic_from_env`] and [`anthropic_new`] build a Messages-format
6//! client. The coding endpoint is
7//! [`ZAI_CODING`](crate::providers::openai::wire::ZAI_CODING). Both read
8//! `ZAI_API_KEY`.
9//!
10//! ```no_run
11//! use rig_core::providers::zai;
12//!
13//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
14//! let glm_4_6 = zai::from_env()?.chat(zai::GLM_4_6);
15//! # let _ = glm_4_6;
16//! # Ok(())
17//! # }
18//! ```
19
20/// General-purpose OpenAI-compatible base URL.
21pub const GENERAL_API_BASE_URL: &str = "https://api.z.ai/api/paas/v4";
22/// Coding-focused OpenAI-compatible base URL.
23pub const CODING_API_BASE_URL: &str = "https://api.z.ai/api/coding/paas/v4";
24/// Anthropic-compatible base URL.
25pub const ANTHROPIC_API_BASE_URL: &str = "https://api.z.ai/api/anthropic";
26
27/// `glm-4.6`
28pub const GLM_4_6: &str = "glm-4.6";
29/// `glm-4.6-air`
30pub const GLM_4_6_AIR: &str = "glm-4.6-air";
31/// `glm-4.6-x`
32pub const GLM_4_6_X: &str = "glm-4.6-x";
33/// `glm-4.5`
34pub const GLM_4_5: &str = "glm-4.5";
35/// `glm-4.5-air`
36pub const GLM_4_5_AIR: &str = "glm-4.5-air";
37/// `glm-4.5v`
38pub const GLM_4_5V: &str = "glm-4.5v";
39/// `glm-4.5-airx`
40pub const GLM_4_5_AIRX: &str = "glm-4.5-airx";
41
42/// Whether GLM `model` reads images: the vision models put `v` right after
43/// the version (`glm-4.5v`, `glm-4.6v-flash`, `glm-5v-turbo`). Every wire
44/// Z.AI serves applies this rule to an id the catalog does not list.
45pub(crate) fn reads_images(model: &str) -> bool {
46 model.strip_prefix("glm-").is_some_and(|rest| {
47 rest.trim_start_matches(|c: char| c.is_ascii_digit() || c == '.')
48 .starts_with('v')
49 })
50}
51
52pub mod extension;
53
54/// The provider key: the dialect name, a reply's `Origin::provider` and
55/// the typed provider-options key.
56pub const PROVIDER_NAME: &str = "zai";
57
58crate::client::macros::openai_vendor!(crate::providers::openai::wire::ZAI, "Z.AI");
59crate::client::macros::anthropic_vendor!(
60 crate::providers::anthropic::wire::ZAI,
61 "Z.AI",
62 anthropic_from_env,
63 anthropic_new
64);