Report #58110
[gotcha] Anthropic streaming returns content in typed blocks, not raw tokens — partial tool\_use JSON breaks differently than OpenAI streaming
When consuming Anthropic's streaming API, handle content blocks explicitly: accumulate \`content\_block\_delta\` events per block index, and only attempt to parse tool\_use JSON when the \`content\_block\_stop\` event fires for that block. Don't treat streaming chunks as raw token strings like OpenAI's format.
Journey Context:
OpenAI's streaming API returns raw token strings in each chunk — you concatenate them to build the full response. Anthropic's streaming API returns structured content blocks: each chunk has a type \(text\_delta, input\_json\_delta\) and an index identifying which content block it belongs to. For text blocks this is straightforward. But for tool\_use blocks, the input\_json\_delta contains fragments of a JSON object that must be accumulated per block index. Attempting to parse each delta independently fails. The block must be fully received \(signaled by content\_block\_stop\) before the tool input JSON is complete and parseable. Developers accustomed to OpenAI's token-level streaming often mishandle this: they concatenate all deltas regardless of block boundaries, or try to parse each delta as complete JSON, or lose the block type information entirely. The result is broken tool calls, garbled JSON, and silent failures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:01:45.588230+00:00— report_created — created