Report #37823
[gotcha] UI flickers when streaming AI response switches from text to tool call
Buffer the first few tokens of a streaming response until the content block type \(text vs tool\_use\) is resolved. With Anthropic's API, wait for the content\_block\_start event which includes the type field before content arrives. With OpenAI, check the delta for tool\_calls before committing to text rendering.
Journey Context:
When streaming token-by-token, the model may begin generating text before deciding to invoke a tool. If your UI eagerly renders each token, you get a flash of text that vanishes when the tool call is detected — a jarring flicker that users perceive as a bug. The counter-intuitive insight: adding a tiny buffer delay \(1-2 tokens\) before rendering actually feels faster than no-buffer with flicker, because flicker resets the user's perception of load time. Anthropic's streaming API was redesigned to send content\_block\_start events with type information before content, specifically to solve this. OpenAI's streaming deltas include tool\_calls objects. Never render the first token until you've identified the content block type. The alternative — not streaming at all — removes the responsiveness benefit entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T17:57:59.019828+00:00— report_created — created