Streaming Issues
Output appears only at the end
Check that the JSON contains "stream": true, curl uses -N, any reverse proxy disables response buffering, and the client reads the stream instead of waiting for response.json().
Output stops midway
Record received events, the finish reason, and any error. Check client total timeout, proxy idle timeout, network changes, upstream termination, and user cancellation. Do not replay tool or write requests automatically.
Broken JSON or corrupted text
A network chunk is not necessarily one complete SSE event. Use an SDK or SSE parser and an incremental UTF-8 decoder:
javascript
// Preserve incomplete UTF-8 bytes between network chunks.
const decoder = new TextDecoder('utf-8')
const reader = response.body.getReader()
while (true) {
// done becomes true only when the response body ends.
const { value, done } = await reader.read()
if (done) break
// stream:true prevents multibyte characters from being decoded too early.
const text = decoder.decode(value, { stream: true })
// Send text to an SSE parser; do not assume it is one complete JSON object.
}Append incremental delta text, but replace accumulated snapshots; mixing them causes duplication. Tool arguments may arrive across multiple events, so wait for the complete call before parsing and executing them.
