Skip to main content

codex_codes/
models.rs

1//! Convenience enum for the models the Codex CLI exposes.
2//!
3//! Variants are keyed by human-friendly model names; [`CodexModel::cli_arg`]
4//! returns the model slug to pass to `codex -m` / `--model`, to
5//! `ThreadStartParams.model`, or to an `AppServerBuilder::config_override`
6//! of `model`.
7//!
8//! The catalog was taken from `openai/codex@main`'s bundled
9//! `models-manager/models.json` (2026-07-11). The server catalog evolves
10//! faster than this crate; GPT-6.1 Sol was verified against the live Codex
11//! catalog and official model documentation (2026-10-04); GPT-6-Sol and
12//! GPT-6-Luna were added from the bundled catalog at `openai/codex@d63a9b83`
13//! (2026-10-06); GPT-6.1 Terra from `openai/codex@126a0ee9` (2026-10-27).
14//! Unknown slugs round-trip through [`CodexModel::Custom`].
15
16use serde::{Deserialize, Deserializer, Serialize, Serializer};
17use std::fmt;
18
19/// A model slug accepted by the Codex CLI and app-server.
20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
21pub enum CodexModel {
22    /// GPT-6.1 Sol (`gpt-6.1-sol`). Availability depends on the server/account.
23    Gpt61Sol,
24    /// GPT-6.1 Terra (`gpt-6.1-terra`). Availability depends on the
25    /// server/account.
26    Gpt61Terra,
27    /// GPT-6-Astra (`gpt-6-astra`) — first GPT-6-family model in the
28    /// catalog (272k context). Live-probed 2026-09-04: the backend
29    /// recognizes the slug but rejects it for ChatGPT-plan auth
30    /// ("not supported when using Codex with a ChatGPT account").
31    Gpt6Astra,
32    /// GPT-6-Sol (`gpt-6-sol`). Availability depends on the server/account.
33    Gpt6Sol,
34    /// GPT-6-Luna (`gpt-6-luna`). Availability depends on the server/account.
35    Gpt6Luna,
36    /// Daybreak Blue (`gpt-daybreak-blue-latest`) — the cyber-access
37    /// program models (see `CyberAccessProgram`); server-side gated.
38    DaybreakBlue,
39    /// Daybreak Red (`gpt-daybreak-red-latest`) — cyber-access program,
40    /// 372k context; server-side gated.
41    DaybreakRed,
42    /// GPT-5.6-Sol (`gpt-5.6-sol`).
43    Gpt56Sol,
44    /// GPT-5.6-Terra (`gpt-5.6-terra`).
45    Gpt56Terra,
46    /// GPT-5.6-Luna (`gpt-5.6-luna`).
47    Gpt56Luna,
48    /// GPT-5.5 (`gpt-5.5`).
49    Gpt55,
50    /// GPT-5.4 (`gpt-5.4`).
51    Gpt54,
52    /// GPT-5.4-Mini (`gpt-5.4-mini`).
53    Gpt54Mini,
54    /// GPT-5.2 (`gpt-5.2`).
55    Gpt52,
56    /// Codex Auto Review (`codex-auto-review`) — hidden from the picker but
57    /// accepted by the API.
58    CodexAutoReview,
59    /// A model slug not yet known to this version of the crate. Passed
60    /// through verbatim.
61    Custom(String),
62}
63
64impl CodexModel {
65    /// The slug to pass to `codex -m` / `ThreadStartParams.model`.
66    pub fn cli_arg(&self) -> &str {
67        match self {
68            Self::Gpt61Sol => "gpt-6.1-sol",
69            Self::Gpt61Terra => "gpt-6.1-terra",
70            Self::Gpt6Astra => "gpt-6-astra",
71            Self::Gpt6Sol => "gpt-6-sol",
72            Self::Gpt6Luna => "gpt-6-luna",
73            Self::DaybreakBlue => "gpt-daybreak-blue-latest",
74            Self::DaybreakRed => "gpt-daybreak-red-latest",
75            Self::Gpt56Sol => "gpt-5.6-sol",
76            Self::Gpt56Terra => "gpt-5.6-terra",
77            Self::Gpt56Luna => "gpt-5.6-luna",
78            Self::Gpt55 => "gpt-5.5",
79            Self::Gpt54 => "gpt-5.4",
80            Self::Gpt54Mini => "gpt-5.4-mini",
81            Self::Gpt52 => "gpt-5.2",
82            Self::CodexAutoReview => "codex-auto-review",
83            Self::Custom(s) => s.as_str(),
84        }
85    }
86
87    /// Alias for [`cli_arg`](Self::cli_arg), matching the crate's string-enum
88    /// convention.
89    pub fn as_str(&self) -> &str {
90        self.cli_arg()
91    }
92
93    /// Human-friendly display name, matching the catalog's `display_name`.
94    pub fn display_name(&self) -> &str {
95        match self {
96            Self::Gpt61Sol => "GPT-6.1-Sol",
97            Self::Gpt61Terra => "GPT-6.1 Terra",
98            Self::Gpt6Astra => "GPT-6-Astra",
99            Self::Gpt6Sol => "GPT-6-Sol",
100            Self::Gpt6Luna => "GPT-6-Luna",
101            Self::DaybreakBlue => "Daybreak Blue",
102            Self::DaybreakRed => "Daybreak Red",
103            Self::Gpt56Sol => "GPT-5.6-Sol",
104            Self::Gpt56Terra => "GPT-5.6-Terra",
105            Self::Gpt56Luna => "GPT-5.6-Luna",
106            Self::Gpt55 => "GPT-5.5",
107            Self::Gpt54 => "GPT-5.4",
108            Self::Gpt54Mini => "GPT-5.4-Mini",
109            Self::Gpt52 => "GPT-5.2",
110            Self::CodexAutoReview => "Codex Auto Review",
111            Self::Custom(s) => s.as_str(),
112        }
113    }
114
115    /// Every model known to this version of the crate.
116    pub fn known() -> &'static [CodexModel] {
117        &[
118            Self::Gpt61Sol,
119            Self::Gpt61Terra,
120            Self::Gpt6Astra,
121            Self::Gpt6Sol,
122            Self::Gpt6Luna,
123            Self::DaybreakBlue,
124            Self::DaybreakRed,
125            Self::Gpt56Sol,
126            Self::Gpt56Terra,
127            Self::Gpt56Luna,
128            Self::Gpt55,
129            Self::Gpt54,
130            Self::Gpt54Mini,
131            Self::Gpt52,
132            Self::CodexAutoReview,
133        ]
134    }
135}
136
137impl fmt::Display for CodexModel {
138    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139        f.write_str(self.cli_arg())
140    }
141}
142
143impl From<&str> for CodexModel {
144    fn from(s: &str) -> Self {
145        match s {
146            "gpt-6.1-sol" => Self::Gpt61Sol,
147            "gpt-6.1-terra" => Self::Gpt61Terra,
148            "gpt-6-astra" => Self::Gpt6Astra,
149            "gpt-6-sol" => Self::Gpt6Sol,
150            "gpt-6-luna" => Self::Gpt6Luna,
151            "gpt-daybreak-blue-latest" => Self::DaybreakBlue,
152            "gpt-daybreak-red-latest" => Self::DaybreakRed,
153            "gpt-5.6-sol" => Self::Gpt56Sol,
154            "gpt-5.6-terra" => Self::Gpt56Terra,
155            "gpt-5.6-luna" => Self::Gpt56Luna,
156            "gpt-5.5" => Self::Gpt55,
157            "gpt-5.4" => Self::Gpt54,
158            "gpt-5.4-mini" => Self::Gpt54Mini,
159            "gpt-5.2" => Self::Gpt52,
160            "codex-auto-review" => Self::CodexAutoReview,
161            other => Self::Custom(other.to_string()),
162        }
163    }
164}
165
166impl From<CodexModel> for String {
167    fn from(model: CodexModel) -> Self {
168        model.cli_arg().to_string()
169    }
170}
171
172impl Serialize for CodexModel {
173    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
174        serializer.serialize_str(self.cli_arg())
175    }
176}
177
178impl<'de> Deserialize<'de> for CodexModel {
179    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
180        let s = String::deserialize(deserializer)?;
181        Ok(Self::from(s.as_str()))
182    }
183}
184
185#[cfg(test)]
186mod tests {
187    use super::CodexModel;
188
189    #[test]
190    fn test_gpt61_sol_catalog_and_wire_round_trip() {
191        let model = CodexModel::from("gpt-6.1-sol");
192        assert_eq!(model, CodexModel::Gpt61Sol);
193        assert!(CodexModel::known().contains(&model));
194        assert_eq!(model.display_name(), "GPT-6.1-Sol");
195        assert_eq!(model.to_string(), "gpt-6.1-sol");
196        let json = serde_json::to_string(&model).unwrap();
197        assert_eq!(json, "\"gpt-6.1-sol\"");
198        assert_eq!(serde_json::from_str::<CodexModel>(&json).unwrap(), model);
199        let slug: String = model.into();
200        assert_eq!(slug, "gpt-6.1-sol");
201    }
202
203    #[test]
204    fn test_gpt6_family_catalog_entries() {
205        for (slug, model, label) in [
206            ("gpt-6-sol", CodexModel::Gpt6Sol, "GPT-6-Sol"),
207            ("gpt-6-luna", CodexModel::Gpt6Luna, "GPT-6-Luna"),
208            ("gpt-6.1-terra", CodexModel::Gpt61Terra, "GPT-6.1 Terra"),
209        ] {
210            assert_eq!(CodexModel::from(slug), model);
211            assert!(CodexModel::known().contains(&model));
212            assert_eq!(model.display_name(), label);
213            let json = serde_json::to_string(&model).unwrap();
214            assert_eq!(json, format!("\"{slug}\""));
215            assert_eq!(serde_json::from_str::<CodexModel>(&json).unwrap(), model);
216        }
217    }
218
219    #[test]
220    fn test_cli_arg_round_trip() {
221        for model in CodexModel::known() {
222            assert_eq!(&CodexModel::from(model.cli_arg()), model);
223        }
224        assert_eq!(
225            CodexModel::from("gpt-9-experimental"),
226            CodexModel::Custom("gpt-9-experimental".to_string())
227        );
228    }
229
230    #[test]
231    fn test_into_string_matches_cli_arg() {
232        let s: String = CodexModel::Gpt56Sol.into();
233        assert_eq!(s, "gpt-5.6-sol");
234    }
235
236    #[test]
237    fn test_converts_into_thread_start_model_field() {
238        // ThreadStartParams.model is Option<String>; the enum feeds it via Into.
239        let model: Option<String> = Some(CodexModel::Gpt55.into());
240        assert_eq!(model.as_deref(), Some("gpt-5.5"));
241    }
242
243    #[test]
244    fn test_serde_round_trip() {
245        let json = serde_json::to_string(&CodexModel::Gpt54Mini).unwrap();
246        assert_eq!(json, "\"gpt-5.4-mini\"");
247        let back: CodexModel = serde_json::from_str(&json).unwrap();
248        assert_eq!(back, CodexModel::Gpt54Mini);
249    }
250}