Error Codes Wiki

Vercel Serverless Function Timeout 504 — What It Means & How to Fix It

Error5xx server error

About Vercel Serverless Function Timeout 504

Fix Vercel serverless function 504 timeout error when your API route or server-side function exceeds the maximum execution time. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: Vercel imposes execution time limits on serverless functions: 10s for Hobby, 60s for Pro, 900s for Enterprise. When a function exceeds this limit, Vercel terminates it and returns a 504 Gateway Timeout. Next.js API routes, getServerSideProps, and Server Actions are all subject to these limits. The function's cold start time is included in the execution limit. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: Database queries taking too long due to missing indexes or large result sets. External API calls timing out or responding slowly. Processing large files or running CPU-intensive computations in the function. Cold starts on the Hobby plan consuming a significant portion of the 10-second limit. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Add maxDuration export to your API route: export const maxDuration = 60; (Pro plan required for > 10s). Move long-running tasks to background jobs using Vercel Cron or a task queue. Optimize database queries with proper indexes and pagination to reduce execution time. Use streaming responses (ReadableStream) to start sending data before processing completes. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

Can I increase the timeout on the free plan?

No. The Hobby (free) plan has a hard limit of 10 seconds for serverless functions. You need to upgrade to the Pro plan for up to 60 seconds or Enterprise for up to 900 seconds.

Overview

Fix Vercel serverless function 504 timeout error when your API route or server-side function exceeds the maximum execution time.

Key Details

  • Vercel imposes execution time limits on serverless functions: 10s for Hobby, 60s for Pro, 900s for Enterprise
  • When a function exceeds this limit, Vercel terminates it and returns a 504 Gateway Timeout
  • Next.js API routes, getServerSideProps, and Server Actions are all subject to these limits
  • The function's cold start time is included in the execution limit

Common Causes

  • Database queries taking too long due to missing indexes or large result sets
  • External API calls timing out or responding slowly
  • Processing large files or running CPU-intensive computations in the function
  • Cold starts on the Hobby plan consuming a significant portion of the 10-second limit

Steps

  1. 1Add maxDuration export to your API route: export const maxDuration = 60; (Pro plan required for > 10s)
  2. 2Move long-running tasks to background jobs using Vercel Cron or a task queue
  3. 3Optimize database queries with proper indexes and pagination to reduce execution time
  4. 4Use streaming responses (ReadableStream) to start sending data before processing completes

Tags

vercel504timeoutserverlessfunction

Related Items

More in 5xx Server Error

Frequently Asked Questions

No. The Hobby (free) plan has a hard limit of 10 seconds for serverless functions. You need to upgrade to the Pro plan for up to 60 seconds or Enterprise for up to 900 seconds.