翻篇收录说明
翻篇网页快照

useChat/useCompletion stream output contains 0:... instead of text | AI SDK

https://ai-sdk.dev/docs/troubleshooting/strange-stream-output

最近抓取:2026-12-04 03:36:23(北京时间)

最近内容变化:2026-12-01 00:24:20(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

How to fix strange stream output in the UI

正文摘录

TroubleshootingMenuuseChat/useCompletion stream output contains 0:... instead of textCopy for LLMView MarkdownAsk AI about this pageIssue I am using custom client code to process a server response that is sent using StreamingTextResponse. I am using version 3.0.20 or newer of the AI SDK. When I send a query, the UI streams text such as 0: "Je", 0: " suis", 0: "des"... instead of the text that I’m looking for. Background The AI SDK has switched to the stream data protocol in version 3.0.20. It sends different stream parts to support data, tool calls, etc. What you see is the raw stream data protocol response. Solution You have several options: Use the AI Core streamText function to send a raw text stream: export async function POST(req: Request) { const { prompt } = await req.json(); const result = streamText({ model: openai.completion('gpt-3.5-turbo-instruct'), maxOutputTokens: 2000, prompt, }); return createTextStreamResponse({ stream: toTextStream({ stream: result.stream }), }); } Pin the AI SDK version to 3.0.19 . This will keep the raw text stream. PreviousServer Actions in Client ComponentsNextStreamable UI Errors