Vercel Serverless Function Timeout - API Routes Taking Too Long
API routes that work fine locally timeout on Vercel. Long-running tasks like file processing, bulk database operations, or external API calls exceed the timeout limit.
Requests return 504 Gateway Timeout and logs show the function was killed.
Error Messages You Might See
Common Causes
- Function execution time exceeds timeout (default 30s, max 60s on Pro)
- Waiting for slow external API calls without timeout
- Database query not optimized or hitting connection limits
- Large file processing happening synchronously
- Missing async/await causing hanging requests
How to Fix It
Upgrade to Vercel Pro for 60s limit (free tier is 30s max)
Add timeout to external calls: fetch(url, { timeout: 10000 })
Use background jobs for long tasks - trigger async processing, return immediately
Optimize DB queries: add indexes, use pagination for large result sets
Consider moving heavy lifting to cron jobs or separate worker services
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
What's the maximum timeout on Vercel?
Free: 30s. Pro: 60s. Enterprise: up to 5min
How do I handle long-running tasks?
Trigger them asynchronously. Save a job record to DB, return immediately, process in background
Should I wait for all async tasks?
No! Return response to user, then run cleanup/processing. Use background jobs for long tasks