← All errors · VercelServerless & Edge Function errors
FUNCTION_INVOCATION_TIMEOUT (504)
Exact error
504: GATEWAY_TIMEOUT. Code: FUNCTION_INVOCATION_TIMEOUT
What it means
A serverless function ran longer than its allowed maximum duration and was stopped.
Likely causes
- Slow external API or database queries.
- Awaiting a promise that never resolves.
- Doing long jobs (AI generation, scraping, big imports) inside a single request.
How to fix it
Find the slow call in the function logs (Vercel dashboard → Logs).
Raise the limit for a route within your plan's allowed maximum:
// app/api/generate/route.ts export const maxDuration = 60; // secondsAdd timeouts to outbound fetches so they fail fast:
await fetch(url, { signal: AbortSignal.timeout(10000) });Move long jobs to a background queue/cron, or stream the response.
Prevent this next time
- Add timeouts to outbound requests and return clear error responses instead of crashing.
- Set up uptime checks and log alerts on critical endpoints so you hear about failures before users do.
Guide: catch outages before your users do.
FAQ
What does "FUNCTION_INVOCATION_TIMEOUT (504)" mean?
A serverless function ran longer than its allowed maximum duration and was stopped.
What usually causes it?
Slow external API or database queries. Awaiting a promise that never resolves. Doing long jobs (AI generation, scraping, big imports) inside a single request.
How do I fix it?
1. Find the slow call in the function logs (Vercel dashboard → Logs). 2. Raise the limit for a route within your plan's allowed maximum: 3. Add timeouts to outbound fetches so they fail fast: 4. Move long jobs to a background queue/cron, or stream the response.
Related errors
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy