Hmbown/CodeWhale · error · anyhow::Error

Responses API error [ ]

Error message

Responses API error [{code}]: {msg}

What it means

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}`.

Solutions

  1. Read the `[code]` and message to identify the API-level failure
  2. Fix the request payload per the reported code (invalid params, unsupported model)
  3. Check account quota/billing if the code indicates limits
  4. Retry if the code indicates a transient server failure
Defensive patterns

Strategy: try-catch

Type guard

fn is_api_failed_event(ev: &Event) -> bool {
    matches!(ev.event_type.as_str(), "error" | "response.failed")
}

Try / catch

if let Err(e) = stream.next().await {
    let msg = e.to_string();
    if let Some(code) = extract_code(&msg) { handle_api_error(code, msg); }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/335f0cd643a6b69b. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/client/responses.rs:537

                                            Some(parse_responses_usage(usage_val));
                                    }
                                    let stop_reason = responses_stop_reason(resp, saw_tool_call);
                                    yield Ok(StreamEvent::MessageDelta {
                                        delta: MessageDelta {
                                            stop_reason: Some(stop_reason),
                                            stop_sequence: None,
                                        },
                                        usage: usage_data.take(),
                                    });
                                }
                                // DeepSeek terminates semantic Responses
                                // streams with this event and deliberately does
                                // not send `data: [DONE]`.
                                done = true;
                            }
                            "error" | "response.failed" => {
                                let (code, msg) = responses_event_error_details(&event);
                                yield Err(anyhow::anyhow!(
                                    "Responses API error [{code}]: {msg}"
                                ));
                                return;
                            }
                            _ => {
                                // Ignore unknown event types.
                            }
                        }
                    }
                }

                if ended {
                    break;
                }
            }

            // Emit MessageStop.
            yield Ok(StreamEvent::MessageStop);

View on GitHub (pinned to 73e0f67d83)