{"record":{"id":"cef81aab07305fbd","repo":"Hmbown/CodeWhale","slug":"responses-api-error-http-status-raw","errorCode":null,"errorMessage":"Responses API error (HTTP {status}): {raw}","messagePattern":"Responses API error \\(HTTP (.+?)\\): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/responses.rs","lineNumber":222,"sourceCode":"                            .header(\"OpenAI-Beta\", \"responses=experimental\")\n                            .header(\"originator\", \"codex_cli_rs\");\n                        if let Some(account_id) = &account_id {\n                            builder = builder.header(\"chatgpt-account-id\", account_id);\n                        }\n                    }\n                    builder.body(request_body.clone())\n                })\n                .await\n                .context(\"Responses API request failed\")\n            }\n        })\n        .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 = bounded_error_text(response, ERROR_BODY_MAX_BYTES).await;\n            anyhow::bail!(\"Responses API error (HTTP {status}): {raw}\");\n        }\n\n        let stream_idle_timeout = self.stream_idle_timeout;\n        let byte_stream = response.bytes_stream();\n\n        let stream = async_stream::stream! {\n            use futures_util::StreamExt;\n\n            // Emit synthetic MessageStart.\n            yield Ok(StreamEvent::MessageStart {\n                message: MessageResponse {\n                    id: String::new(),\n                    r#type: \"message\".to_string(),\n                    role: \"assistant\".to_string(),\n                    content: vec![],\n                    model: wire_model.clone(),\n                    stop_reason: None,\n                    stop_sequence: None,","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client/responses.rs#L204-L240","documentation":"When opening a Responses API stream, the client first checks the HTTP status before consuming the byte stream. A non-success status (4xx/5xx) means the request failed at the API layer; the client reads a bounded amount of the error body and bails with the status code and raw body so the caller sees the upstream failure detail.","triggerScenarios":"handle_responses_stream (via create_message_stream or handle_responses_message) receives an HTTP response whose status.is_success() is false — e.g. 401 invalid key, 429 rate limit, 400 bad request, 5xx upstream outage — when calling the provider's Responses endpoint.","commonSituations":"Expired or wrong API key (401/403); malformed request payload or unsupported parameters (400); quota exhaustion (429); provider outage (5xx); hitting a wrong base URL path.","solutions":["Read the {raw} body in the message — it contains the provider's error JSON explaining the cause","For 401/403, fix the API key/credentials and account permissions","For 429, back off and retry respecting rate limits","For 400, correct the request parameters/model name; for 5xx, retry later or check provider status"],"exampleFix":"// before: single attempt\nlet response = self.send(request).await?;\n// after: retry transient upstream failures with backoff\nlet response = retry_with_backoff(3, || async {\n    let resp = self.send(request.clone()).await?;\n    if resp.status().is_server_error() { bail!(\"transient {status}\") }\n    Ok(resp)\n}).await?;","handlingStrategy":"retry","validationCode":"// preflight: validate credentials and endpoint reachability\nassert!(!api_key.is_empty(), \"missing API key for Responses endpoint\");","typeGuard":null,"tryCatchPattern":"match stream_request().await {\n    Err(e) if e.to_string().contains(\"Responses API error\") => {\n        if e.to_string().contains(\"HTTP 429\") || e.to_string().contains(\"HTTP 5\") {\n            backoff_retry(|| stream_request()).await\n        } else {\n            Err(e) // 4xx client errors are not retryable\n        }\n    }\n    other => other,\n}","preventionTips":["Validate API keys and model names before issuing stream requests","Respect rate limits with client-side throttling","Monitor provider status pages for 5xx windows","Log the bounded error body — it names the exact upstream cause"],"tags":["http","responses-api","upstream-api","streaming"],"backgroundTag":"http-error-response","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}