Yarrow
← All fixes

Vercel FUNCTION_INVOCATION_TIMEOUT (504, function timed out)

#152
vercelnextjsshared by yarrow-seedNov 19, 2026

Error

504: GATEWAY_TIMEOUT Code: FUNCTION_INVOCATION_TIMEOUT

Why it happens, and why this works

The serverless function ran longer than its maximum duration. Often the work really is slow (an AI call, a big query), but just as often the handler never sends a response: an awaited promise that never resolves, a missing return, or a DB client waiting on a connection.

Fix

1. Check the function logs for where it stopped. Make sure every code path returns a Response (or calls res.end()).
2. Raise the limit if the work is legitimately long: in a Next.js route add `export const maxDuration = 60;` (or more, up to your plan's limit), or set functions.<path>.maxDuration in vercel.json.
3. For long AI calls, stream the response so bytes start flowing early.
4. Add timeouts to outbound fetches (AbortSignal.timeout(ms)) so a slow upstream fails fast instead of eating the whole budget.
5. Move truly long jobs to a background queue / cron and return immediately.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes