{"record":{"id":"8bb59d7222c4f0bb","repo":"Hmbown/CodeWhale","slug":"failed-to-call-deepseek-chat-api-http-status","errorCode":null,"errorMessage":"Failed to call DeepSeek Chat API: HTTP {status}: {error_text}","messagePattern":"Failed to call DeepSeek Chat API: HTTP (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/chat.rs","lineNumber":1141,"sourceCode":"            None\n        };\n\n        // The endpoint was resolved by the shared seam alongside the body, so\n        // a route-shape decision (e.g. DeepSeek's strict-tools `/beta` path)\n        // cannot be made twice with two different answers.\n        let url = prepared.endpoint.url.as_str();\n        let response = self.send_json_with_retry(url, body).await?;\n\n        let status = response.status();\n        crate::client::record_provider_response(self.api_provider, status.as_u16());\n        if !status.is_success() {\n            let raw_error_text = bounded_error_text(response, ERROR_BODY_MAX_BYTES).await;\n            let error_text = sanitize_http_error_body(\n                Some(self.api_provider.display_name()),\n                status.as_u16(),\n                &raw_error_text,\n            );\n            anyhow::bail!(\"Failed to call DeepSeek Chat API: HTTP {status}: {error_text}\");\n        }\n\n        let response_text = response\n            .text()\n            .await\n            .context(\"Failed to read Chat API response body\")?;\n        let value: Value =\n            serde_json::from_str(&response_text).context(\"Failed to parse Chat API JSON\")?;\n        let parsed = parse_chat_message_for_route(&value, self.api_provider, &self.base_url)?;\n        if let Some(key) = response_cache_key {\n            crate::llm_response_cache::response_cache().put(key, parsed.clone());\n        }\n        Ok(parsed)\n    }\n}\n\nimpl DeepSeekClient {\n    async fn open_chat_stream_response(","sourceCodeStart":1123,"sourceCodeEnd":1159,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/client/chat.rs#L1123-L1159","documentation":"The non-streaming DeepSeek Chat API call returned a non-2xx status. The response body is bounded to `ERROR_BODY_MAX_BYTES` and passed through `sanitize_http_error_body` before formatting, and the status is recorded via `record_provider_response`. The sanitized provider message is embedded verbatim.","triggerScenarios":"401 invalid API key; 402 insufficient DeepSeek balance; 404 wrong model name or base URL; 422 invalid parameters; 429 rate limit; 500/503 provider errors.","commonSituations":"Expired or mistyped API key; drained DeepSeek account balance; renamed/deprecated model IDs; misconfigured base URL pointing at the wrong endpoint; bursts hitting rate limits.","solutions":["Read the HTTP status and embedded error text first — they map directly to the cause","401/402: fix the API key or top up the DeepSeek account balance","429: back off and retry; reduce request frequency","404/400: verify the model ID and base URL against DeepSeek's current docs"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"fn is_retryable_http_status_from_message(msg: &str) -> bool {\n    [408, 409, 429, 500, 502, 503, 504]\n        .iter()\n        .any(|s| msg.contains(&format!(\"HTTP {s}\")))\n}","tryCatchPattern":"match client.send(request).await {\n    Err(e) if is_retryable_http_status_from_message(&e.to_string()) => {\n        backoff_retry(client, request, MAX_ATTEMPTS).await\n    }\n    Err(e) if e.to_string().contains(\"HTTP 401\") || e.to_string().contains(\"HTTP 402\") => {\n        Err(e) // credential/balance: never retry, surface to the user\n    }\n    result => result,\n}","preventionTips":["Validate the API key and account balance before long batches of DeepSeek calls","Verify model IDs against current DeepSeek docs at config time","Apply exponential backoff on 429 instead of immediate retries"],"tags":["deepseek","http","api","status-code"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}