{"record":{"id":"76e260ea6d9cfea7","repo":"zed-industries/zed","slug":"failed-to-connect-to-mistral-api","errorCode":null,"errorMessage":"Failed to connect to Mistral API: {} {}","messagePattern":"Failed to connect to Mistral API: (.+?) (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/mistral/src/mistral.rs","lineNumber":458,"sourceCode":"                    Ok(line) => {\n                        let line = line.strip_prefix(\"data: \")?;\n                        if line == \"[DONE]\" {\n                            None\n                        } else {\n                            match serde_json::from_str(line) {\n                                Ok(response) => Some(Ok(response)),\n                                Err(error) => Some(Err(anyhow!(error))),\n                            }\n                        }\n                    }\n                    Err(error) => Some(Err(anyhow!(error))),\n                }\n            })\n            .boxed())\n    } else {\n        let mut body = String::new();\n        response.body_mut().read_to_string(&mut body).await?;\n        anyhow::bail!(\n            \"Failed to connect to Mistral API: {} {}\",\n            response.status(),\n            body,\n        );\n    }\n}\n","sourceCodeStart":440,"sourceCodeEnd":465,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/mistral/src/mistral.rs#L440-L465","documentation":"Raised by Zed's Mistral provider when POSTing to {api_url}/chat/completions returns a non-success HTTP status. The response body is drained and embedded verbatim next to the status code, so authentication, quota, model, and upstream-server failures all surface through this single message.","triggerScenarios":"Any Mistral chat/stream completion call where the API answers 401 (bad/expired API key), 403, 404 (wrong model name in the request payload), 422, 429 (rate limit/quota), or 5xx. Note the request already carries `Authorization: Bearer <api_key>`; a missing key fails earlier.","commonSituations":"Expired or mistyped MISTRAL_API_KEY; quota exhausted on the Mistral plan; requesting a model the key has no access to; corporate proxies returning HTML error pages with a 502/503.","solutions":["Read the status code and body inside the message: 401/403 → fix the API key in Zed's assistant settings; 404/400 → verify the model identifier; 429 → wait or raise rate limits; 5xx → retry shortly","Confirm the key works outside Zed: curl https://api.mistral.ai/v1/chat/completions with the same key and model","Check corporate proxy/VPN interference if the body is an HTML error page","Retry after a short backoff — transient 429/5xx responses commonly clear on their own"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"async fn key_works(client: &dyn HttpClient, api_key: &str) -> bool {\n    // cheap auth probe before wiring the provider\n    let req = HttpRequest::get(\"https://api.mistral.ai/v1/models\")\n        .header(\"Authorization\", format!(\"Bearer {}\", api_key.trim()));\n    matches!(client.send(req).await, Ok(resp) if resp.status().is_success())\n}","typeGuard":null,"tryCatchPattern":"match stream_chat_completion(request).await {\n    Err(err) => {\n        let msg = err.to_string();\n        if msg.contains(\"429\") || msg.contains(\"50\") && msg.contains(\"Mistral API\") {\n            backoff.then_retry().await; // transient: rate limit / upstream\n        } else if msg.contains(\"401\") {\n            prompt_for_new_api_key();\n        } else {\n            show_error(msg); // body text carries the provider detail\n        }\n    }\n    Ok(stream) => stream,\n}","preventionTips":["Validate the API key with a cheap /v1/models call at configuration time","Confirm model identifiers against current Mistral docs before hardcoding","Wrap streaming calls in retry-with-backoff for 429/5xx only, never for 401/404","Watch the embedded response body — it distinguishes auth vs quota vs model errors"],"tags":["mistral","llm","http","api","authentication","network"],"backgroundTag":"http-api-request-failed","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"}