504 Gateway Timeout: FUNCTION_INVOCATION_TIMEOUT
- Vercel
- Netlify
- Serverless functions
What it means
Your server function ran longer than the hosting plan allows, so the platform stopped it and returned a 504. It worked locally because your laptop has no time limit.
Why it happens
- A slow AI call, export or report runs inside a normal request.
- A database query that was fast with test data is slow with real data.
- The function waits on an external service that is slow or down.
How to fix it
- Check the function's duration in your host's logs and its limit on your plan.
- Move long work to a background job and let the page check for the result.
- Stream AI responses instead of waiting for the whole answer.
- Add indexes for slow queries, and timeouts for external calls.
Let your AI find the cause
Paste this into Claude Code, Cursor, Lovable or whichever AI built your app. It looks first and changes nothing until you have read the answer.
Some requests in my app fail with a 504 / FUNCTION_INVOCATION_TIMEOUT in production. Without changing anything yet, find the slow route, list everything it waits on (database queries, AI calls, external APIs) and estimate how long each takes. Propose how to restructure it so no request runs longer than a few seconds.