Report #59891
[gotcha] Streaming structured output \(JSON mode, function calls\) crashes your UI because partial JSON fragments are unparseable
Buffer streamed tokens until finish\_reason is received, then parse the complete JSON. If you need progressive rendering, use a streaming-safe JSON parser \(e.g., jsonrepair, partial-json\) that handles incomplete documents. Never pass raw delta content through JSON.parse\(\) on each chunk.
Journey Context:
Streaming works seamlessly for plain text — each token renders as it arrives. But when you enable JSON mode or function calling, each streamed chunk contains a fragment of the JSON object. Naively parsing each chunk with JSON.parse\(\) throws SyntaxError because the JSON is incomplete until the final chunk. Developers often don't discover this in testing because short responses may complete within a single chunk, masking the bug. It only surfaces in production with longer responses that span many chunks. The tradeoff: buffering adds latency \(defeating streaming's purpose\), but progressive parsing without a resilient parser breaks the UI. The right call is buffer-then-parse for correctness, or use an incremental JSON parser if progressive rendering is critical.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T07:00:47.486411+00:00— report_created — created