{"record":{"id":"7a70635f11d19538","repo":"zed-industries/zed","slug":"completion-request-failed-code-code-message","errorCode":null,"errorMessage":"completion request failed, code: {code}, message: {message}","messagePattern":"completion request failed, code: (.+?), message: (.+?)","errorType":"exception","errorClass":"LanguageModelCompletionError","httpStatus":null,"severity":"error","filePath":"crates/language_model_core/src/language_model_core.rs","lineNumber":252,"sourceCode":"        host: String,\n        #[source]\n        error: anyhow::Error,\n    },\n    #[error(\"error deserializing {provider} API response\")]\n    DeserializeResponse {\n        provider: LanguageModelProviderName,\n        #[source]\n        error: serde_json::Error,\n    },\n    #[error(\"stream from {provider} ended unexpectedly\")]\n    StreamEndedUnexpectedly { provider: LanguageModelProviderName },\n    #[error(transparent)]\n    Other(#[from] anyhow::Error),\n}\n\nimpl LanguageModelCompletionError {\n    fn parse_upstream_error_json(message: &str) -> Option<(StatusCode, String)> {\n        let error_json = serde_json::from_str::<serde_json::Value>(message).ok()?;\n        let upstream_status = error_json\n            .get(\"upstream_status\")\n            .and_then(|v| v.as_u64())\n            .and_then(|status| u16::try_from(status).ok())\n            .and_then(|status| StatusCode::from_u16(status).ok())?;\n        let inner_message = error_json\n            .get(\"message\")\n            .and_then(|v| v.as_str())\n            .unwrap_or(message)\n            .to_string();\n        Some((upstream_status, inner_message))\n    }\n\n    pub fn from_cloud_failure(\n        upstream_provider: LanguageModelProviderName,\n        code: String,\n        message: String,\n        retry_after: Option<Duration>,","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/zed-industries/zed/blob/5a9b9558db01a6b906cec2fb70a797affdc58cdd/crates/language_model_core/src/language_model_core.rs#L234-L270","documentation":"Error variant carrying a failed completion request from the cloud gateway: `from_cloud_failure` (with parse_upstream_error_json as its JSON-decoding helper) wraps the gateway's error code and message when a request to the model provider fails upstream. The code classifies the failure (prompt too large, upstream HTTP error, rate limit, etc.) so callers can decide on retry behavior; the message is what the upstream provider returned.","triggerScenarios":"Thrown at crates/language_model_core/src/language_model_core.rs:243 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read `code` to classify: prompt-too-long means shrink the context, upstream_http_error means the underlying provider failed","Respect any retry_after duration before retrying","Retry transient upstream errors (5xx) with backoff; do not retry 4xx request errors unchanged","If the gateway consistently fails, check provider status and the configured API endpoint"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5a9b9558db01a6b906cec2fb70a797affdc58cdd","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}