# Vercel: 504 GATEWAY_TIMEOUT — FUNCTION_INVOCATION_TIMEOUT: An error occurred with your deployment

**Code:** `Vercel FUNCTION_INVOCATION_TIMEOUT (504)` · **Category:** Next.js · **Seen on:** Next.js

A Vercel Serverless Function ran longer than its max duration, so Vercel killed it.

## Meaning

Default limits are 10 s (Hobby) up to 60-300 s depending on plan/config. Raise `export const maxDuration = 60` in the route (within your plan), speed up the work (indexes, parallel requests), or move long jobs to a queue/background function. Cold starts and slow DB connections also count.

## Common causes

- Slow database or external API
- Heavy computation in the request
- Cold start + connection setup
- maxDuration left at default
- No timeout/retry around upstream calls

## Quick fix

1. `export const maxDuration = 60;` in the route/page (plan-dependent)
2. Optimise queries and parallelise requests
3. Offload long tasks to queues/Cron/Workflow

## Detailed fix by platform

### Next.js

1. `export const maxDuration = 60; // seconds, route segment config`

## How to diagnose

1. **Duration** — Over the limit?
2. **Cause** — DB/API/CPU?
3. **Plan** — Limit?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nextjs/vercel-function-timeout)
