sigoden/aichat · error
Invalid response event-stream. content-type
Error message
Invalid response event-stream. content-type: {content_type}, data: {text} What it means
The streaming endpoint responded with a Content-Type that is not text/event-stream (e.g. application/json from a non-streaming API, or text/html from an error page). This means the request reached an HTTP server but not a valid SSE endpoint — typically a wrong base URL, a model/endpoint that does not support streaming, or a proxy stripping the event-stream content type. The response body is dumped to aid diagnosis.
Solutions
- Verify the base URL and path target a streaming-capable SSE endpoint
- Check that the model supports streaming and that the request was formed with stream: true
- If behind a proxy, ensure it preserves the text/event-stream Content-Type and does not buffer the response
- Compare the dumped body with provider docs to identify whether an error JSON was returned instead of a stream
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/client/stream.rs:128 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/33fc55432a0d7034.
Report an issue: GitHub.
Appendix: source
Thrown at src/client/stream.rs:128
Err(err) => {
match err {
EventSourceError::StreamEnded => {}
EventSourceError::InvalidStatusCode(status, res) => {
let text = res.text().await?;
let data: Value = match text.parse() {
Ok(data) => data,
Err(_) => {
bail!(
"Invalid response data: {text} (status: {})",
status.as_u16()
);
}
};
catch_error(&data, status.as_u16())?;
}
EventSourceError::InvalidContentType(header_value, res) => {
let text = res.text().await?;
bail!(
"Invalid response event-stream. content-type: {}, data: {text}",
header_value.to_str().unwrap_or_default()
);
}
_ => {
bail!("{}", err);
}
}
es.close();
}
}
}
Ok(())
}
pub async fn json_stream<S, F, E>(mut stream: S, mut handle: F) -> Result<()>
where
S: Stream<Item = Result<bytes::Bytes, E>> + Unpin,View on GitHub (pinned to 82976d349a)