Report #93263
[gotcha] Streaming tool\_calls JSON is invalid until the full response completes
Accumulate all delta.tool\_calls fragments into a buffer and only parse the JSON after finish\_reason becomes non-null. For progressive UI rendering of tool calls, implement a partial JSON parser or show a placeholder until the complete function call is available.
Journey Context:
When streaming responses that include tool\_calls, each chunk contains a fragment of the JSON arguments as a delta string. These fragments are not valid JSON on their own — they are substrings of the complete JSON object. Developers who try to JSON.parse each chunk's tool\_calls arguments will get syntax errors. The temptation is to show users what tool the AI is calling in real-time, but the arguments arrive character-by-character and cannot be rendered meaningfully until complete. The tradeoff is between showing a loading indicator for the tool call \(accurate but less informative\) versus trying to progressively render partial arguments \(engaging but fragile and error-prone\). The safe default is to buffer and parse only on completion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:07:38.602644+00:00— report_created — created