{"record":{"id":"31cc71b9d9945502","repo":"zed-industries/zed","slug":"cannot-fetch-anthropic-models-without-an-api-key","errorCode":null,"errorMessage":"cannot fetch Anthropic models without an API key","messagePattern":"cannot fetch Anthropic models without an API key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/language_models/src/provider/anthropic.rs","lineNumber":108,"sourceCode":"            credentials_provider,\n            cx,\n        );\n\n        cx.spawn(async move |this, cx| {\n            let result = task.await;\n            if result.is_ok() {\n                this.update(cx, |this, cx| this.restart_fetch_models_task(cx))\n                    .ok();\n            }\n            result\n        })\n    }\n\n    fn fetch_models(&mut self, cx: &mut Context<Self>) -> Task<Result<()>> {\n        let http_client = self.http_client.clone();\n        let api_url = AnthropicLanguageModelProvider::api_url(cx);\n        let Some(api_key) = self.api_key_state.key(&api_url) else {\n            return Task::ready(Err(anyhow::anyhow!(\n                \"cannot fetch Anthropic models without an API key\"\n            )));\n        };\n        let extra_headers = AnthropicLanguageModelProvider::settings(cx)\n            .custom_headers\n            .clone();\n\n        cx.spawn(async move |this, cx| {\n            let models = anthropic::list_models(\n                http_client.as_ref(),\n                &api_url,\n                api_key.as_ref(),\n                &extra_headers,\n            )\n            .await\n            .map_err(LanguageModelCompletionError::from)?;\n\n            this.update(cx, |this, cx| {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/language_models/src/provider/anthropic.rs#L90-L126","documentation":"Early-return guard in AnthropicLanguageModelProvider::fetch_models: `api_key_state.key(&api_url)` returned None, so there is no Anthropic API key with which to call the models list endpoint. Model listing requires authentication; this fires when fetch_models runs (e.g. via restart_fetch_models_task after authenticate) before the user has provided credentials.","triggerScenarios":"Thrown at crates/language_models/src/provider/anthropic.rs:108 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Sign in / enter an Anthropic API key in the provider settings so authenticate() can store it","Check that the credentials provider has a stored key for the configured api_url","If using a custom base URL, ensure credentials exist for that URL, not just the default"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}