Report #40378
[gotcha] AI API errors mid-stream after partial content already rendered to user
Design your UI state machine to treat partial streamed responses as valid terminal states: show an inline error indicator at the truncation point, preserve already-rendered content as selectable and copyable, and offer 'continue generation' rather than replacing the entire response with an error screen
Journey Context:
Traditional error handling assumes a clean binary: either you get a complete response or you show an error state before any content renders. Streaming breaks this completely. When an LLM stream fails mid-generation — content filter triggered, max\_tokens reached, API timeout, rate limit — you have already rendered paragraphs of valid content. Wiping it with a generic error message is both jarring and lossy; the user loses good content they may have already started reading. The architectural gotcha: your component state machine likely has states like loading → success \| error, but streaming requires loading → streaming → \(complete \| partial\+error\), where the error state must coexist with rendered content. The right pattern: detect stream termination events \(finish\_reason: 'content\_filter', 'length'\) distinctly from connection errors, render a visual boundary at the cutoff point \(e.g., a faded divider with 'Generation stopped: content policy triggered'\), keep the partial content interactive, and offer contextual recovery actions like 'retry from here' or 'rephrase your question'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:14:46.704513+00:00— report_created — created