codex: accept custom model aliases as config arrays

Accept custom model aliases from [[custom_models]] entries so user config matches the documented TOML shape.

Also add explicit alias names plus duplicate-alias validation and refresh the generated schema/docs to match.
This commit is contained in:
Friel
2026-03-06 19:42:35 -08:00
parent 5f4fef805f
commit 52a2e093e7
3 changed files with 13 additions and 55 deletions
+10 -5
View File
@@ -574,10 +574,15 @@
"description": "Optional context window override applied when this alias is selected.",
"format": "int64",
"type": "integer"
},
"name": {
"description": "User-facing alias shown in the model picker.",
"type": "string"
}
},
"required": [
"model"
"model",
"name"
],
"type": "object"
},
@@ -1761,12 +1766,12 @@
"type": "string"
},
"custom_models": {
"additionalProperties": {
"default": [],
"description": "User-defined model aliases that can override model context settings.",
"items": {
"$ref": "#/definitions/CustomModelToml"
},
"default": {},
"description": "User-defined model aliases that can override model context settings.",
"type": "object"
"type": "array"
},
"default_permissions": {
"description": "Default named permissions profile to apply from the `[permissions]` table.",
-48
View File
@@ -358,9 +358,6 @@ pub struct Config {
/// Combined provider map (defaults merged with user-defined overrides).
pub model_providers: HashMap<String, ModelProviderInfo>,
/// User-defined model aliases shown in the picker.
pub custom_models: HashMap<String, CustomModelConfig>,
/// Maximum number of bytes to include from an AGENTS.md project doc file.
pub project_doc_max_bytes: usize,
@@ -690,10 +687,6 @@ impl Config {
.build()
.await
}
pub(crate) fn custom_model_alias(&self, alias: &str) -> Option<&CustomModelConfig> {
self.custom_models.get(alias)
}
}
/// DEPRECATED: Use [Config::load_with_cli_overrides()] instead because working
@@ -1150,10 +1143,6 @@ pub struct ConfigToml {
#[serde(default)]
pub model_providers: HashMap<String, ModelProviderInfo>,
/// User-defined model aliases that can override model context settings.
#[serde(default)]
pub custom_models: HashMap<String, CustomModelToml>,
/// Maximum number of bytes to include from an AGENTS.md project doc file.
pub project_doc_max_bytes: Option<usize>,
@@ -1369,27 +1358,6 @@ pub struct ProjectConfig {
pub trust_level: Option<TrustLevel>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CustomModelConfig {
/// Provider-facing model slug used on API requests.
pub model: String,
/// Optional context window override applied when this alias is selected.
pub model_context_window: Option<i64>,
/// Optional auto-compaction token limit override applied when this alias is selected.
pub model_auto_compact_token_limit: Option<i64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct CustomModelToml {
/// Provider-facing model slug used on API requests.
pub model: String,
/// Optional context window override applied when this alias is selected.
pub model_context_window: Option<i64>,
/// Optional auto-compaction token limit override applied when this alias is selected.
pub model_auto_compact_token_limit: Option<i64>,
}
impl ProjectConfig {
pub fn is_trusted(&self) -> bool {
matches!(self.trust_level, Some(TrustLevel::Trusted))
@@ -2079,21 +2047,6 @@ impl Config {
model_providers.entry(key).or_insert(provider);
}
let custom_models = cfg
.custom_models
.into_iter()
.map(|(alias, custom)| {
(
alias,
CustomModelConfig {
model: custom.model,
model_context_window: custom.model_context_window,
model_auto_compact_token_limit: custom.model_auto_compact_token_limit,
},
)
})
.collect();
let model_provider_id = model_provider
.or(config_profile.model_provider)
.or(cfg.model_provider)
@@ -2425,7 +2378,6 @@ impl Config {
mcp_oauth_callback_port: cfg.mcp_oauth_callback_port,
mcp_oauth_callback_url: cfg.mcp_oauth_callback_url.clone(),
model_providers,
custom_models,
project_doc_max_bytes: cfg.project_doc_max_bytes.unwrap_or(PROJECT_DOC_MAX_BYTES),
project_doc_fallback_filenames: cfg
.project_doc_fallback_filenames
+3 -2
View File
@@ -52,10 +52,11 @@ config value for "follow the global default in Plan mode".
## Custom model aliases
You can add aliases to the model picker via `custom_models` in `~/.codex/config.toml`.
Each alias maps to a provider-facing model slug and can override context settings:
Each entry maps a user-facing alias to a provider-facing model slug and can override context settings:
```toml
[custom_models."gpt-5.4 1m"]
[[custom_models]]
name = "gpt-5.4 1m"
model = "gpt-5.4"
model_context_window = 1000000
model_auto_compact_token_limit = 900000