{"record":{"id":"759c061f936342bb","repo":"zed-industries/zed","slug":"codestral-api-error","errorCode":null,"errorMessage":"Codestral API error: {} - {}","messagePattern":"Codestral API error: (.+?) - (.+?)","errorType":"http","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codestral/src/codestral.rs","lineNumber":165,"sourceCode":"\n        log::debug!(\"Codestral: Sending FIM request\");\n\n        let http_request = http_client::Request::builder()\n            .method(http_client::Method::POST)\n            .uri(format!(\"{}/v1/fim/completions\", api_url))\n            .header(\"Content-Type\", \"application/json\")\n            .header(\"Authorization\", format!(\"Bearer {}\", api_key))\n            .body(http_client::AsyncBody::from(request_body))?;\n\n        let mut response = http_client.send(http_request).await?;\n        let status = response.status();\n\n        log::debug!(\"Codestral: Response status: {}\", status);\n\n        if !status.is_success() {\n            let mut body = String::new();\n            response.body_mut().read_to_string(&mut body).await?;\n            return Err(anyhow::anyhow!(\n                \"Codestral API error: {} - {}\",\n                status,\n                body\n            ));\n        }\n\n        let mut body = String::new();\n        response.body_mut().read_to_string(&mut body).await?;\n\n        let codestral_response: CodestralResponse = serde_json::from_str(&body)?;\n\n        let elapsed = start_time.elapsed();\n\n        if let Some(choice) = codestral_response.choices.first() {\n            let completion = &choice.message.content;\n\n            log::debug!(\n                \"Codestral: Completion received ({} tokens, {:.2}s)\",","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/codestral/src/codestral.rs#L147-L183","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: surfacing raw error\nlet response = http_client.send(http_request).await?;\n\n// after: classify status before failing\nlet status = response.status();\nif status == StatusCode::UNAUTHORIZED {\n    anyhow::bail!(\"Codestral API key rejected; update your credentials\");\n}\nif !status.is_success() {\n    anyhow::bail!(\"Codestral API error: {} - {}\", status, body);\n}","handlingStrategy":"try-catch","validationCode":"// validate request inputs before sending\nif api_key.is_empty() {\n    anyhow::bail!(\"Codestral API key is empty\");\n}\nif !KNOWN_MODELS.contains(&model.as_str()) {\n    anyhow::bail!(\"unknown Codestral model: {model}\");\n}","typeGuard":null,"tryCatchPattern":"let status = response.status();\nif status == StatusCode::UNAUTHORIZED {\n    anyhow::bail!(\"Codestral rejected the API key; update credentials\");\n}\nif status == StatusCode::TOO_MANY_REQUESTS {\n    // retryable: honor Retry-After if present\n    let wait = response\n        .headers()\n        .get(\"Retry-After\")\n        .and_then(|v| v.to_str().ok())\n        .and_then(|v| v.parse::<u64>().ok())\n        .unwrap_or(5);\n    executor.timer(Duration::from_secs(wait)).await;\n    return self.complete(request_body).await;\n}\nif !status.is_success() {\n    anyhow::bail!(\"Codestral API error: {} - {}\", status, body);\n}","preventionTips":["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"],"tags":["api","llm","http","codestral"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}