{"record":{"id":"335f0cd643a6b69b","repo":"Hmbown/CodeWhale","slug":"responses-api-error-code-msg","errorCode":null,"errorMessage":"Responses API error [{code}]: {msg}","messagePattern":"Responses API error \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/responses.rs","lineNumber":537,"sourceCode":"                                            Some(parse_responses_usage(usage_val));\n                                    }\n                                    let stop_reason = responses_stop_reason(resp, saw_tool_call);\n                                    yield Ok(StreamEvent::MessageDelta {\n                                        delta: MessageDelta {\n                                            stop_reason: Some(stop_reason),\n                                            stop_sequence: None,\n                                        },\n                                        usage: usage_data.take(),\n                                    });\n                                }\n                                // DeepSeek terminates semantic Responses\n                                // streams with this event and deliberately does\n                                // not send `data: [DONE]`.\n                                done = true;\n                            }\n                            \"error\" | \"response.failed\" => {\n                                let (code, msg) = responses_event_error_details(&event);\n                                yield Err(anyhow::anyhow!(\n                                    \"Responses API error [{code}]: {msg}\"\n                                ));\n                                return;\n                            }\n                            _ => {\n                                // Ignore unknown event types.\n                            }\n                        }\n                    }\n                }\n\n                if ended {\n                    break;\n                }\n            }\n\n            // Emit MessageStop.\n            yield Ok(StreamEvent::MessageStop);","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client/responses.rs#L519-L555","documentation":"The Responses API sent an `error` or `response.failed` SSE event, meaning the server rejected or failed the generation after (or instead of) streaming. The client extracts a code and message via `responses_event_error_details` and surfaces them as `Responses API error [{code}]: {msg}`.","triggerScenarios":"The stream dispatches an SSE event with type `\"error\"` or `\"response.failed\"`; handle_responses_stream extracts (code, msg) and returns immediately (crates/tui/src/client/responses.rs:537).","commonSituations":"Invalid request parameters accepted at HTTP level but rejected at API level, provider-side model failures, quota/billing issues surfacing as stream errors, or content-policy refusals mid-stream.","solutions":["Read the `[code]` and message to identify the API-level failure","Fix the request payload per the reported code (invalid params, unsupported model)","Check account quota/billing if the code indicates limits","Retry if the code indicates a transient server failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_api_failed_event(ev: &Event) -> bool {\n    matches!(ev.event_type.as_str(), \"error\" | \"response.failed\")\n}","tryCatchPattern":"if let Err(e) = stream.next().await {\n    let msg = e.to_string();\n    if let Some(code) = extract_code(&msg) { handle_api_error(code, msg); }\n}","preventionTips":["Validate request payload against the Responses API schema","Check quota/billing before long sessions","Handle error/response.failed events explicitly","Map known API codes to user actions"],"tags":["api","streaming","sse","responses-api"],"backgroundTag":"api-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"}