sigoden/aichat · error

Unsupported model

Error message

Unsupported model '{name}'

What it means

Emitted by the `unsupported_model!` macro (src/client/macros.rs:243), which bails with "Unsupported model '<name>'". It signals that a model name given to the library does not map to any client/model combination the library knows how to route.

Solutions

  1. Check the model name spelling against the provider's model list (/v1/models).
  2. Ensure the model is included in the client's configured models (set_client_models_config) so routing can find it.
  3. Prefix the model with the client name (client:model) if the library supports that form.
  4. Upgrade the library if the model was added in a newer provider catalog.

Example fix

// before
let model = "gpt4o"; // typo
// after
let model = "gpt-4o";
Defensive patterns

Strategy: validation

Validate before calling

// ensure the model is configured/routable before use
let configured: Vec<String> = config.clients.iter().flat_map(|c| c.models.iter().map(|m| m.name.clone())).collect();
if !configured.contains(&model.to_string()) {
    anyhow::bail!("model '{}' not configured", model);
}

Type guard

fn model_is_configured(model: &str, config: &Config) -> bool {
    config.clients.iter().any(|c| c.models.iter().any(|m| m.name == model))
}

Try / catch

match run_with_model(model).await {
    Err(e) if e.to_string().starts_with("Unsupported model") => {
        eprintln!("'{}' unknown; run fetch_models or fix the name", model)
    }
    other => other,
}

Prevention

When it happens

Trigger: Passing a model identifier to a client/API entry point whose name doesn't correspond to a registered model for any client — typically when dispatching on model name fails in macros that select the client by model.

Common situations: Typo in the model name; model exists only on a newer provider version; using a model alias not present in the client's configured models list; mixing model names across clients (e.g. OpenAI name on an Ollama client).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/a38f1e289a15c5ea. Report an issue: GitHub.

Appendix: source

Thrown at src/client/macros.rs:243

#[macro_export]
macro_rules! config_get_fn {
    ($field_name:ident, $fn_name:ident) => {
        fn $fn_name(&self) -> anyhow::Result<String> {
            let env_prefix = Self::name(&self.config);
            let env_name =
                format!("{}_{}", env_prefix, stringify!($field_name)).to_ascii_uppercase();
            std::env::var(&env_name)
                .ok()
                .or_else(|| self.config.$field_name.clone())
                .ok_or_else(|| anyhow::anyhow!("Miss '{}'", stringify!($field_name)))
        }
    };
}

#[macro_export]
macro_rules! unsupported_model {
    ($name:expr) => {
        anyhow::bail!("Unsupported model '{}'", $name)
    };
}

View on GitHub (pinned to 82976d349a)