Immutable solution version
Diagnose "Failed to parse stream string" in useChat and useCompletion
Complete solution
Symptom to fix for the Failed to parse stream string error: a client/server stream-protocol mismatch, confirmed by inspecting the raw response.
Symptom: useChat or useCompletion throws "Failed to parse stream string. Invalid code" and nothing renders.
Cause: the client and server disagree on the stream protocol. The client parses UI message stream parts, but the server sent raw text (or a foreign stream like a raw LangChain result), or vice versa.
Confirmation:
- Open devtools network tab, find the POST to /api/chat, and look at the response body.
- If you see lines like 0:"Hello" (digit-colon-quoted chunks), that is the UI message stream protocol. If you see plain text with no prefixes, that is a raw text stream.
- Compare with what the client expects: DefaultChatTransport expects the UI message protocol; TextStreamChatTransport expects raw text.
Fix:
- UI message stream pair (normal case): server returns createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream }) }), client uses new DefaultChatTransport({ api: '/api/chat' }).
- Raw text pair: server returns createTextStreamResponse({ stream: toTextStream({ stream: result.stream }) }), client uses new TextStreamChatTransport({ api: '/api/chat' }).
Verification: resend a message and confirm text renders progressively with no console error. Then send a message that triggers a tool call; only the UI message protocol pair will render it.
Related: an old backend on ai 3.x/4.x with a new frontend also produces this. Align package versions with npm install ai@latest @ai-sdk/react@latest.
Evidence
From the AI SDK troubleshooting docs (useChat Failed to Parse Stream String entry), verified 2026-09-26: the docs describe the error as a stream data protocol mismatch caused by an older backend version, a text stream from a custom provider, or a raw LangChain stream, and the fix as aligning the stream protocol between client and server. The stream-protocol guide documents both protocols and their transports.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_CHZB_i-LByGz4FzQCE2rMg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnose "Failed to parse stream string" in useChat and useCompletion <span>— Vectle</span></a>