Solution skill
UIMessageStreamError: the outgoing UI message stream is invalid
Complete solution
Shows how to fix uIMessageStreamError: the outgoing UI message stream is invalid. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
If you only use toUIMessageStream({ stream: result.stream }), you will basically never see this. Then re-add parts one at a time.
Steps
- UIMessageStreamError means the stream you handed to createUIMessageStreamResponse contained a part that violates the UI message stream protocol. The model call may have succeeded; the packaging failed.
- import { createUIMessageStream, createUIMessageStreamResponse } from 'ai';
const stream = createUIMessageStream({ execute({ writer }) { writer.write({ type: 'text-start', id: 'x' }); // every part must match the protocol's part types },
});
- What to know:
- If you only use toUIMessageStream({ stream: result.stream }), you will basically never see this. It appears when you build streams manually with createUIMessageStream or inject custom parts.
- Common trigger: a custom part with a type string that is not in the protocol, or a part missing required fields like id.
- Another trigger: writing parts after the stream closed, or writing a start part without its matching end part.
- InvalidStreamPartError is the lower-level sibling for data stream parts. Same idea: the part does not match the expected shape.
- When it fires, isolate by removing your custom writer code and confirming the plain toUIMessageStream path works. Then re-add parts one at a time.
- Keep the stream-protocol doc page open while writing custom parts. The protocol is versioned with the SDK; v7 part types are the reference, not a blog post from v4.
When to use
You are seeing this: UIMessageStreamError means the stream you handed to createUIMessageStreamResponse contained a part that violates the UI message stream protocol. Use this skill when you run into "UIMessageStreamError: the outgoing UI message stream is invalid".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Verified against the live AI SDK docs 2026-09-26. The errors reference lists UIMessageStreamError and InvalidStreamPartError under inputs and message streams. The stream-protocol guide documents the UI message stream part types for custom implementations.
By @issueatlas · Version 2 · 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_eysfKe29hKWGsnvfCcNCcw" 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">UIMessageStreamError: the outgoing UI message stream is invalid <span>— Vectle</span></a>