{"record":{"id":"bee5378a79594bd3","repo":"zed-industries/zed","slug":"anthropic-api-key-environment-variable-not-set","errorCode":null,"errorMessage":"ANTHROPIC_API_KEY environment variable not set","messagePattern":"ANTHROPIC_API_KEY environment variable not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_cli/src/anthropic_client.rs","lineNumber":29,"sourceCode":"use sqlez::bindable::Bind;\nuse sqlez::bindable::StaticColumnCount;\nuse sqlez_macros::sql;\nuse std::collections::HashSet;\nuse std::hash::Hash;\nuse std::hash::Hasher;\nuse std::path::Path;\nuse std::sync::{Arc, Mutex};\n\npub struct PlainLlmClient {\n    pub http_client: Arc<dyn HttpClient>,\n    pub api_key: String,\n}\n\nimpl PlainLlmClient {\n    pub fn new() -> Result<Self> {\n        let http_client: Arc<dyn http_client::HttpClient> = Arc::new(ReqwestClient::new());\n        let api_key = std::env::var(\"ANTHROPIC_API_KEY\")\n            .map_err(|_| anyhow::anyhow!(\"ANTHROPIC_API_KEY environment variable not set\"))?;\n        Ok(Self {\n            http_client,\n            api_key,\n        })\n    }\n\n    pub async fn generate(\n        &self,\n        model: &str,\n        max_tokens: u64,\n        messages: Vec<Message>,\n    ) -> Result<AnthropicResponse> {\n        let request = AnthropicRequest {\n            model: model.to_string(),\n            max_tokens,\n            messages,\n            tools: Vec::new(),\n            thinking: None,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_cli/src/anthropic_client.rs#L11-L47","documentation":"PlainLlmClient::new reads the ANTHROPIC_API_KEY environment variable to build the client; std::env::var failed (unset or non-unicode), so the client cannot authenticate. The missing environment variable is the input at fault.","triggerScenarios":"Thrown at crates/edit_prediction_cli/src/anthropic_client.rs:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Export ANTHROPIC_API_KEY with a valid key before running the tool","Add the variable to the shell profile or .env file used by the CLI"],"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-14T05:17:10.506Z"}