Common IssuesGetting Timeouts When Deploying on Vercel
Getting Timeouts When Deploying on Vercel
Issue
Streaming with the AI SDK works in my local development environment.
However, when I'm deploying to Vercel, longer responses get chopped off in the UI and I'm seeing timeouts in the Vercel logs or I'm seeing the error: Uncaught (in promise) Error: Connection closed
.
Solution
If you are using Next.js with the App Router, you can add the following to your route file or the page you are calling your Server Action from:
export const maxDuration = 30;
This increases the maximum duration of the function to 30 seconds.
For other frameworks such as Svelte, you can set timeouts in your vercel.json
file:
{ "functions": { "api/chat/route.ts": { "maxDuration": 30 } }}