Report #76300
[gotcha] Streaming AI responses break when parsing tool call arguments mid-stream
Accumulate all delta chunks for tool\_call function arguments into a buffer before attempting JSON.parse. Never parse individual deltas — they are string fragments, not valid JSON objects.
Journey Context:
Developers build streaming handlers that work fine for text content, then add tool support and get JSON parse errors on every chunk. OpenAI streams tool call arguments as incremental string deltas in choices\[0\].delta.tool\_calls\[\].function.arguments. Each chunk contains a fragment like '\{"lo' then 'cation' then '":"NYC"\}' — none are parseable alone. The trap is that text content streams cleanly token-by-token, lulling you into treating all streamed fields the same way. You must concatenate all argument deltas per tool\_call index and only parse the assembled string once the stream closes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:39:50.559475+00:00— report_created — created