zed-industries/zed · error · anyhow::Error
Codestral API error: {} - {}
Error message
Codestral API error: {} - {} What it means
A completion request to the Codestral API returned a non-success HTTP status; the status code and full response body are embedded in the error. The body normally contains the API's own explanation (invalid key, unknown model, rate limit).
Source
Thrown at crates/codestral/src/codestral.rs:165
log::debug!("Codestral: Sending FIM request");
let http_request = http_client::Request::builder()
.method(http_client::Method::POST)
.uri(format!("{}/v1/fim/completions", api_url))
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", api_key))
.body(http_client::AsyncBody::from(request_body))?;
let mut response = http_client.send(http_request).await?;
let status = response.status();
log::debug!("Codestral: Response status: {}", status);
if !status.is_success() {
let mut body = String::new();
response.body_mut().read_to_string(&mut body).await?;
return Err(anyhow::anyhow!(
"Codestral API error: {} - {}",
status,
body
));
}
let mut body = String::new();
response.body_mut().read_to_string(&mut body).await?;
let codestral_response: CodestralResponse = serde_json::from_str(&body)?;
let elapsed = start_time.elapsed();
if let Some(choice) = codestral_response.choices.first() {
let completion = &choice.message.content;
log::debug!(
"Codestral: Completion received ({} tokens, {:.2}s)",View on GitHub (pinned to bc538def45)
Solutions
- Read the status/body in the message: 401 → fix the API key, 429 → slow down or raise quota, 404 → fix the model name
- Verify the key with a minimal curl request to the Codestral API
- Add backoff/retry only for 429 and 5xx, never for 4xx auth errors
Example fix
// before: surfacing raw error
let response = http_client.send(http_request).await?;
// after: classify status before failing
let status = response.status();
if status == StatusCode::UNAUTHORIZED {
anyhow::bail!("Codestral API key rejected; update your credentials");
}
if !status.is_success() {
anyhow::bail!("Codestral API error: {} - {}", status, body);
} Defensive patterns
Strategy: try-catch
Validate before calling
// validate request inputs before sending
if api_key.is_empty() {
anyhow::bail!("Codestral API key is empty");
}
if !KNOWN_MODELS.contains(&model.as_str()) {
anyhow::bail!("unknown Codestral model: {model}");
} Try / catch
let status = response.status();
if status == StatusCode::UNAUTHORIZED {
anyhow::bail!("Codestral rejected the API key; update credentials");
}
if status == StatusCode::TOO_MANY_REQUESTS {
// retryable: honor Retry-After if present
let wait = response
.headers()
.get("Retry-After")
.and_then(|v| v.to_str().ok())
.and_then(|v| v.parse::<u64>().ok())
.unwrap_or(5);
executor.timer(Duration::from_secs(wait)).await;
return self.complete(request_body).await;
}
if !status.is_success() {
anyhow::bail!("Codestral API error: {} - {}", status, body);
} Prevention
- Never retry 401/403 — fix the key instead
- Rate-limit inline completion requests locally to avoid 429s
- Log status plus body once per failure; the body names the real cause
When it happens
Trigger: POST to the Codestral completion endpoint returns 401 (bad API key), 429 (rate limit/quota), 400/404 (invalid model name or malformed request body), or 5xx.
Common situations: Expired or mistyped API key in Zed's Codestral settings; using a model name the key's plan does not allow; bursts of inline-completion requests exceeding quotas.
Related errors
- No completion returned from Codestral
- Sentry API returned HTTP {error.code} for {path}: {detail}
- Sentry API returned HTTP {err.code} for {path}: {detail}
- Failed to get authenticated user. Status: {:?} Body: {body}
- Claude returned no tool_use block for tool '{tool['name']}'
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/759c061f936342bb.
Report an issue: GitHub.