{"record":{"id":"61e8858520e06124","repo":"sigoden/aichat","slug":"no-available-model","errorCode":null,"errorMessage":"No available model","messagePattern":"No available model","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/config/mod.rs","lineNumber":2393,"sourceCode":"        if let Some(Some(v)) = read_env_bool(&get_env_name(\"save_shell_history\")) {\n            self.save_shell_history = v;\n        }\n        if let Some(v) = read_env_value::<String>(&get_env_name(\"sync_models_url\")) {\n            self.sync_models_url = v;\n        }\n    }\n\n    fn load_functions(&mut self) -> Result<()> {\n        self.functions = Functions::init(&Self::functions_file())?;\n        Ok(())\n    }\n\n    fn setup_model(&mut self) -> Result<()> {\n        let mut model_id = self.model_id.clone();\n        if model_id.is_empty() {\n            let models = list_models(self, ModelType::Chat);\n            if models.is_empty() {\n                bail!(\"No available model\");\n            }\n            model_id = models[0].id()\n        };\n        self.set_model(&model_id)?;\n        self.model_id = model_id;\n        Ok(())\n    }\n\n    fn setup_document_loaders(&mut self) {\n        [(\"pdf\", \"pdftotext $1 -\"), (\"docx\", \"pandoc --to plain $1\")]\n            .into_iter()\n            .for_each(|(k, v)| {\n                let (k, v) = (k.to_string(), v.to_string());\n                self.document_loaders.entry(k).or_insert(v);\n            });\n    }\n\n    fn setup_user_agent(&mut self) {","sourceCodeStart":2375,"sourceCodeEnd":2411,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L2375-L2411","documentation":"Thrown by GlobalConfig::setup_model() during initialization when no model_id is configured AND list_models(self, ModelType::Chat) returns an empty vector — i.e. no usable chat model could be resolved from any provider configuration. The tool cannot proceed without at least one model.","triggerScenarios":"Starting aichat (REPL/CMD/serve startup calls setup_model) with: no `model` in config.yaml, all providers missing/invalid API keys so no models register, or provider config present but exposing zero chat models.","commonSituations":"Fresh install without any provider configured; API keys unset in env/config so provider init is skipped; typo'd provider name in config.yaml; all providers filtered out by platform restrictions.","solutions":["Configure at least one provider with a valid API key in config.yaml (or env var), then set `model: <provider>:<model>`.","Set the model explicitly in config.yaml or via the `--model` flag so list_models resolution is bypassed.","Verify provider config with `aichat --list-models` and fix the provider that yields zero models."],"exampleFix":"// config.yaml — before\nclients: []\n// after\nclients:\n  - type: openai\n    api_key: sk-...\nmodel: openai:gpt-4o","handlingStrategy":"validation","validationCode":"let ok = !config.read().model_id.is_empty() || !list_models(&config, ModelType::Chat).is_empty(); if !ok { eprintln!(\"configure a provider and model in config.yaml\"); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = config.write().setup_model() { if e.to_string() == \"No available model\" { eprintln!(\"Set `model:` and provider api_key in config.yaml\"); std::process::exit(1); } return Err(e.into()); }","preventionTips":["Run `aichat --list-models` after any config change","Always set a provider api_key plus `model:` in config.yaml","Validate config before deploying to fresh environments"],"tags":["model","config","provider","startup"],"backgroundTag":"missing-config-value","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}