zed-industries/zed · error
ANTHROPIC_API_KEY environment variable not set
Error message
ANTHROPIC_API_KEY environment variable not set
What it means
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.
Source
Thrown at crates/edit_prediction_cli/src/anthropic_client.rs:29
use sqlez::bindable::Bind;
use sqlez::bindable::StaticColumnCount;
use sqlez_macros::sql;
use std::collections::HashSet;
use std::hash::Hash;
use std::hash::Hasher;
use std::path::Path;
use std::sync::{Arc, Mutex};
pub struct PlainLlmClient {
pub http_client: Arc<dyn HttpClient>,
pub api_key: String,
}
impl PlainLlmClient {
pub fn new() -> Result<Self> {
let http_client: Arc<dyn http_client::HttpClient> = Arc::new(ReqwestClient::new());
let api_key = std::env::var("ANTHROPIC_API_KEY")
.map_err(|_| anyhow::anyhow!("ANTHROPIC_API_KEY environment variable not set"))?;
Ok(Self {
http_client,
api_key,
})
}
pub async fn generate(
&self,
model: &str,
max_tokens: u64,
messages: Vec<Message>,
) -> Result<AnthropicResponse> {
let request = AnthropicRequest {
model: model.to_string(),
max_tokens,
messages,
tools: Vec::new(),
thinking: None,View on GitHub (pinned to f4178619ac)
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/edit_prediction_cli/src/anthropic_client.rs:29 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20).
Data as JSON: /api/errors/bee5378a79594bd3.
Report an issue: GitHub.