logo
Course

Deploy on Vercel

Loading...
Warning

If you're encountering an execution timeout after deployment when "Generating AI Answer," it's because Vercel (or any deployment provider but not Framework i.e., Next.js) enforces a time limit on how long a function can run. Since calling OpenAI to generate a response can take longer than a typical API request, you might hit that limit.

To fix this, you can increase the allowed execution time by setting maxDuration for your endpoint:

app/api/ai/answers/route.ts
export const maxDuration = 5;

Learn more about how maxDuration works here.

Another way to speed things up is to run the API endpoint closer to your users by switching the runtime to the Edge Network. This reduces the distance between your user and the server handling the request, leading to faster responses.

You don't need complex setup — just add this line to your endpoint file:

app/api/ai/answers/route.ts
export const runtime = "edge";

With this, your AI API will now run on a server closer to your users, making it faster and more efficient.