Skip to content

Commit 68fd43d

Browse files
authored
docs: improve troubleshooting pages (#1540)
1 parent ec07fbf commit 68fd43d

6 files changed

+61
-31
lines changed

content/docs/08-troubleshooting/01-common-issues/04-strange-stream-output.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: Strange Stream Output
2+
title: useChat/useCompletion stream output contains 0:... instead of text
33
description: How to fix strange stream output in the UI
44
---
55

6-
# Strange Stream Outputs
6+
# useChat/useCompletion stream output contains 0:... instead of text
77

88
## Issue
99

content/docs/08-troubleshooting/01-common-issues/06-streaming-not-working-in-production.mdx

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Streaming Not Working When Deploying on Vercel
3+
description: Troubleshooting errors related to streaming not working when deploying on Vercel.
4+
---
5+
6+
# Streaming Not Working When Deploying on Vercel
7+
8+
## Issue
9+
10+
Streaming with the AI SDK works in my local dev environment. I'm using the app router and I'm deploying to Vercel.
11+
However, streaming does not work in the deployed app. Instead of streaming, only the full response is returned after a while.
12+
13+
## Solution
14+
15+
Add the following to your route file:
16+
17+
```tsx
18+
export const dynamic = 'force-dynamic';
19+
```
20+
21+
This will enforce dynamic behavior, which is required for streaming.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Getting Timeouts When Deploying on Vercel
3+
description: Troubleshooting errors related to streaming not working when deploying on Vercel.
4+
---
5+
6+
# Getting Timeouts When Deploying on Vercel
7+
8+
## Issue
9+
10+
Streaming with the AI SDK works in my local dev environment.
11+
I'm using the app router and I'm deploying to Vercel.
12+
However, I'm getting timeouts.
13+
14+
## Solution
15+
16+
Add the following to your route file:
17+
18+
```tsx
19+
export const maxDuration = 60;
20+
export const dynamic = 'force-dynamic';
21+
```
22+
23+
This will enforce dynamic behavior, which is required for streaming.
24+
25+
## See also
26+
27+
- [Configuring Maximum Duration for Vercel Functions](https://vercel.com/docs/functions/configuring-functions/duration)

content/docs/08-troubleshooting/01-common-issues/07-unclosed-streams.mdx

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ Sometimes streams are not closed properly, which can lead to unexpected behavior
1313

1414
## Solution
1515

16-
This happens when you create a streamable UI using [`createStreamableUI`](/docs/reference/ai-sdk-rsc/create-streamable-ui) and fail to close the stream. In order to fix this, you must ensure you close the stream by calling the [`.done()`](/docs/reference/ai-sdk-rsc/create-streamable-ui#done) method. This will ensure the stream is closed.
16+
This happens when you create a streamable UI using [`createStreamableUI`](/docs/reference/ai-sdk-rsc/create-streamable-ui) and fail to close the stream.
17+
In order to fix this, you must ensure you close the stream by calling the [`.done()`](/docs/reference/ai-sdk-rsc/create-streamable-ui#done) method.
18+
This will ensure the stream is closed.
1719

1820
```tsx file='app/actions.ts'
1921
import { createStreamableUI } from 'ai/rsc';
20-
import { nanoid } from 'nanoid';
2122

2223
const submitMessage = async () => {
2324
'use server';
@@ -28,9 +29,6 @@ const submitMessage = async () => {
2829
stream.append('3');
2930
stream.done('4'); // [!code ++]
3031

31-
return {
32-
id: nanoid(),
33-
display: stream.value,
34-
};
32+
return stream.value,
3533
};
3634
```

content/docs/08-troubleshooting/01-common-issues/08-use-chat-failed-to-parse-stream.mdx

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ description: Troubleshooting errors related to the Use Chat Failed to Parse Stre
77

88
## Issue
99

10-
I am using `useChat` or `useCompletion` and I’m getting a `"Failed to parse stream string. Invalid code"` error. I am using version `3.0.20` or newer of the AI SDK.
10+
I am using `useChat` or `useCompletion` and I am getting a `"Failed to parse stream string. Invalid code"` error. I am using version `3.0.20` or newer of the AI SDK.
1111

1212
## Background
1313

14-
The AI SDK has switched to the stream data protocol in version `3.0.20` . `useChat` and `useCompletion` expect stream parts that support data, tool calls, etc. What you see is a failure to parse the stream. This can be caused by using an older version of the AI SDK in the backend, by providing a text stream using a custom provider, or by using a raw LangChain stream result.
14+
The AI SDK has switched to the stream data protocol in version `3.0.20`.
15+
`useChat` and `useCompletion` expect stream parts that support data, tool calls, etc.
16+
What you see is a failure to parse the stream.
17+
This can be caused by using an older version of the AI SDK in the backend, by providing a text stream using a custom provider, or by using a raw LangChain stream result.
1518

1619
## Solution
1720

18-
You can switch `useChat` and `useCompletion` to raw text stream processing with the `streamMode` parameter (introduced in `v3.0.23` of the AI SDK). Just set it to `text` as follows:
21+
You can switch `useChat` and `useCompletion` to raw text stream processing with the `streamMode` parameter (introduced in `v3.0.23` of the AI SDK).
22+
Set it to `text` as follows:
1923

2024
```tsx
2125
const { messages, append } = useChat({

0 commit comments

Comments
 (0)