Report #82976
[gotcha] Streaming structured output returns invalid partial JSON that crashes parsers
Use an incremental JSON parser \(e.g., partial-json, json-stream\) or buffer the complete response before parsing. Never pass raw SSE delta chunks into JSON.parse\(\). For OpenAI, accumulate delta content or delta.tool\_calls\[\].arguments strings across all chunks and parse only after the stream closes with finish\_reason: 'stop'.
Journey Context:
Structured output \(JSON mode, function calling\) works perfectly without streaming because the full JSON object is returned at once. When streaming is enabled, each Server-Sent Event chunk contains only a fragment — a few tokens of the JSON string. Developers who test without streaming first, then enable it later, hit JSON.parse\(\) errors on incomplete objects like '\{"name": "Al'. The trap is that some chunks happen to land on valid JSON boundaries by coincidence, making the bug appear intermittent. This is especially painful because the error often surfaces in production with real streaming traffic, not in local testing where latency is low and chunk sizes differ.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:51:40.714443+00:00— report_created — created