Hmbown/CodeWhale · error

invalid Runtime Chat model id

Error message

invalid Runtime Chat model id

What it means

`validate_model_id` checks Runtime Chat model identifiers against `runtime_chat_model_id_is_safe` before the relay stores or sends them. A model id with characters outside the safe set is rejected to keep persisted records and requests well-formed.

Solutions

  1. Verify the model id matches the safe format (typically `provider/model` allowed only if the predicate accepts it; otherwise use the canonical id).
  2. Use the model id exactly as returned by the model registry instead of hand-editing it.
  3. Normalize/trim the id before passing it in.

Example fix

// before
let model = " openai/gpt-4 ";
relay.validate_model_id(model)?;
// after
let model = " openai/gpt-4 ".trim();
relay.validate_model_id(model)?; // or use the registry's canonical id
Defensive patterns

Strategy: validation

Validate before calling

fn is_safe_model_id(id: &str) -> bool { !id.is_empty() && id == id.trim() && id.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.' | '/')) }
if !is_safe_model_id(&model_id) { return Err(format!("model id not safe: {model_id}")); }

Type guard

fn safe_model_id(id: &str) -> Option<&str> { (!id.is_empty() && id.trim() == id).then_some(id) }

Try / catch

match relay.validate_model_id(&model_id) { Err(e) => { eprintln!("{e}; using registry id instead"); use_registry_model_id() }, Ok(_) => proceed() }

Prevention

When it happens

Trigger: Calling a Runtime Chat relay API with a model id string that fails the safety predicate (unsafe characters, separators, injection-prone content).

Common situations: Copy-pasting a model name with slashes or whitespace from vendor docs; composing model ids dynamically from untrusted provider metadata.

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


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/8c37fedc036eb4c5. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/runtime_chat_relay.rs:1755

        || !value
            .bytes()
            .all(|byte| byte.is_ascii_alphanumeric() || byte == b'_')
    {
        bail!("invalid {label}");
    }
    Ok(())
}

fn validate_route_id(value: &str, label: &str) -> Result<()> {
    if !crate::runtime_api::runtime_chat_route_id_is_safe(value) {
        bail!("invalid Runtime Chat {label}");
    }
    Ok(())
}

fn validate_model_id(value: &str) -> Result<()> {
    if !crate::runtime_api::runtime_chat_model_id_is_safe(value) {
        bail!("invalid Runtime Chat model id");
    }
    Ok(())
}

fn validate_fingerprint(value: &str) -> Result<()> {
    if value.len() != 64 || !value.bytes().all(|byte| byte.is_ascii_hexdigit()) {
        bail!("invalid Runtime Chat fingerprint");
    }
    Ok(())
}

fn fingerprint(value: &str) -> String {
    hex_digest(Sha256::digest(value.as_bytes()))
}

fn runtime_chat_request_fingerprint(command: &RuntimeChatPrompt) -> Result<String, String> {
    serde_json::to_value(command)
        .map(|value| canonical_json_value(&value))

View on GitHub (pinned to 73e0f67d83)