Hmbown/CodeWhale · error
invalid model id for `model_context_windows`
Error message
invalid model id for `model_context_windows`
What it means
Keys of the form model_context_windows.<provider>.<model> are validated before the window value: the model id may not be the literal `auto` and may not contain whitespace or control characters. `auto` is a reserved sentinel and malformed ids would create entries that never match a real model.
Solutions
- Use the exact model id without spaces (quote the whole key in your shell)
- Do not use `auto` as a model key; set the provider-level default context_window instead
- Verify the model id matches what the provider API returns (e.g. gpt-4o, not "gpt 4o")
Example fix
// before codewhale config set 'model_context_windows.openai.auto' 128000 // after codewhale config set 'model_context_windows.openai.gpt-4o' 128000
Defensive patterns
Strategy: validation
Validate before calling
if model.eq_ignore_ascii_case("auto") || model.chars().any(|c| c.is_whitespace() || c.is_control()) {
return Err("invalid model id for model_context_windows");
} Type guard
fn valid_model_key(model: &str) -> bool {
!model.eq_ignore_ascii_case("auto") && !model.chars().any(|c| c.is_whitespace() || c.is_control())
} Try / catch
match config.set_model_context_window(provider, model, value) {
Err(e) if e.to_string().contains("invalid model id") => eprintln!("use exact model id, no spaces, not 'auto'"),
other => other?,
} Prevention
- Quote dotted keys in shell commands
- Take model ids from provider API listings, not prose
- Never use `auto` as a per-model key; use provider-level defaults
When it happens
Trigger: set_model_context_window called with model == "auto" (case-insensitive) or a model string containing spaces/tabs/control characters — e.g. `config set model_context_windows.openai.some model 200000`.
Common situations: Trying to set a wildcard/default window using `auto`; pasting a model name with a stray space or line break from docs; shell quoting issues injecting whitespace into the key.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- fleet task worker.model cannot be empty
- Invalid configured model
- .model_context_windows. must be greater than 0
- agent profile provider cannot be empty
- agent profile provider must be a simple provider id
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/e356c19bdcb5998b.
Report an issue: GitHub.
Appendix: source
Thrown at crates/config/src/lib.rs:2670
"kind"
} else {
ProviderConfigField::parse(field_key).map_or(field_key, |field| field.key())
};
table.remove(leg);
}
/// Write one `[providers.<id>.model_context_windows]` entry (#6108),
/// whether `<id>` is a built-in provider key or a named custom table.
fn set_model_context_window(
&mut self,
provider_id: &str,
model: &str,
value: &str,
) -> Result<()> {
if model.eq_ignore_ascii_case("auto")
|| model.chars().any(|c| c.is_whitespace() || c.is_control())
{
bail!("invalid model id for `model_context_windows`");
}
let window = parse_context_window(value)?;
if let Some(kind) = builtin_provider_kind_for_config_id(provider_id) {
self.providers
.for_provider_mut(kind)
.model_context_windows
.insert(model.to_string(), window);
return Ok(());
}
let table = self.custom_provider_table_mut(provider_id)?;
let windows = table
.entry("model_context_windows".to_string())
.or_insert_with(|| toml::Value::Table(toml::value::Table::new()));
windows
.as_table_mut()
.with_context(|| {
format!("providers.{provider_id}.model_context_windows must be a table")
})?View on GitHub (pinned to 73e0f67d83)