{"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":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/responses.rs","lineNumber":502,"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\n            // Emit MessageStop.\n            yield Ok(StreamEvent::MessageStop);\n        };\n\n        Ok(Box::pin(stream))\n    }","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/client/responses.rs#L484-L520","documentation":"The provider's Responses-API stream delivered an event of type error or response.failed after the stream was already underway. responses_event_error_details extracts a machine code and human message, and the client terminates with 'Responses API error [code]: msg' (crates/tui/src/client/responses.rs:502) instead of treating the response as complete. DeepSeek deliberately ends semantic Responses streams this way instead of sending data: [DONE].","triggerScenarios":"Mid-stream failures after a 200: content-policy rejections once output starts, model not enabled for this account, provider overload, tool definitions that only fail at execution time, or a genuine response.failed terminal event.","commonSituations":"API key scoped to models it cannot serve; org rate-limited mid-generation; Responses-API emulation gateways that fail on tool calls; expired keys that pass header auth but fail on the event bus.","solutions":["Read the bracketed code first - it maps to the provider's documented error taxonomy","Verify the key can call this exact model with a plain non-streaming curl","For permission/content codes, fix the request payload (tools, instructions); do not retry","Retry with backoff only for overload/timeout-style codes - auth and validation codes fail identically","If a gateway fronts the provider, test the provider directly to see which side synthesized the event"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight the same model non-streaming to surface auth/model errors before the stream\nlet resp = client.post(\"/responses\").json(&minimal_request_for(model)).send().await?;\nensure!(resp.status().is_success(), \"pre-flight failed: {}\", resp.status());","typeGuard":"fn is_responses_api_error(msg: &str) -> bool {\n    msg.starts_with(\"Responses API error [\")\n}\n\nfn responses_error_code(msg: &str) -> Option<&str> {\n    msg.strip_prefix(\"Responses API error [\")?.split(']').next()\n}","tryCatchPattern":"// Branch on the bracketed code: retry overload, fail fast on auth/validation\nif let Some(code) = responses_error_code(&e.to_string()) {\n    match code {\n        \"overloaded_error\" | \"timeout\" => retry_with_backoff().await,\n        _ => return Err(e), // 4xx-class codes are deterministic\n    }\n}","preventionTips":["Pre-flight model access with a tiny non-streaming call when switching keys","Keep tool schemas valid - some providers only validate them mid-stream","Map provider error codes to retry policies instead of retrying everything"],"tags":["api","responses-api","provider","streaming","error-event"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}