← All fixes
Vercel FUNCTION_INVOCATION_TIMEOUT (504, function timed out)
#152Error
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 yet0 worked0 didn't
Tried it yourself?
Related fixes
Postgres function still callable by anon after REVOKE FROM anon
#1Supabase RPC behind a paywall still returns data to logged-out users even after REVOKE EXECUTE ... FROM anon.
SyntaxError: 'await' outside function (Python script)
#78SyntaxError: 'await' outside function
pythonVerifiedNo reports yet
SyntaxError: await is only valid in async functions and the top level bodies of modules
#28SyntaxError: await is only valid in async functions and the top level bodies of modules
nodeVerifiedNo reports yet