FUNCTION_INVOCATION_TIMEOUT is Vercel's 504 Gateway Timeout: the function ran past its max duration, 300 s on Hobby. Hand the encode to ReelSDK with ?wait=0 and a webhook_url; it runs at $0.02 per compute minute.
FUNCTION_INVOCATION_TIMEOUT
One core took about 87 seconds to encode a 28-second 1080p clip in our test. ReelSDK answered the same job in under a second with a 202 and finished it about 27 seconds later. Vercel's limits come from its docs.
ErrorsUpdated
FUNCTION_INVOCATION_TIMEOUT: Gateway Timeout
Source: Vercel: FUNCTION_INVOCATION_TIMEOUT, checked November 2026.
Where it shows up
A Vercel Function that runs ffmpeg, or waits for it
You run ffmpeg inside a route handler or API route, or call a render service and hold the request open until the video is done. Short clips pass. A longer clip, or a slower preset, gets a 504 back and Vercel logs FUNCTION_INVOCATION_TIMEOUT, which its error list files under Function errors.
Vercel's page for the error also names a slow network call, a function that never returns a response, an infinite loop and an unhandled exception. For ffmpeg the usual cause is plainer: the encode needs more time than the function has.
Why it happens
The encode needs more time than the function gets
Vercel terminates any invocation that runs past its max duration. With fluid compute, which is on by default, that is 300 s on Hobby, and on Pro and Enterprise 300 s by default and up to 800 s. Hobby always gets 1 vCPU, and Pro and Enterprise start at 1 vCPU too.
libx264 is CPU bound, so encode time grows with the clip. We pinned ffmpeg to one core of our sandbox and re-encoded a 28-second vertical clip with the default preset, and it took a little over 3 times the clip's length. At that rate 300 s covers about a minute and a half of footage. Your function's vCPU is not our core, but the shape is the same.
Causes and fixes
Vercel's limits next to this encode
| Item | Value |
|---|---|
| Hobby max duration | 300 s, also the default |
| Pro and Enterprise max duration | 800 s, or 1800 s per function in beta |
| Default function CPU | 1 vCPU with 2 GB |
| 28 s clip, default preset, one core | About 87 s |
| Same clip, -preset veryfast | About 41 s |
| Killed after 30 s | A third of the frames, file unreadable |
| ReelSDK with ?wait=0 | 202 in under a second, webhook when done |
Source: Vercel function duration docs, checked November 2026.
The local fix
Raise maxDuration and make the encode faster
Set maxDuration on the route: an exported constant in the Next.js App Router, or the functions block of vercel.json elsewhere. 300 is the Hobby ceiling. Pro and Enterprise can go to 800, or to 1800 per function in the extended beta.
Then cut the encode time. On the same core, -preset veryfast took less than half as long, about 41 seconds instead of 87. Neither change removes the ceiling: an encode that runs longer than the limit still fails, so measure your longest input before you rely on it.
// app/api/render/route.ts
export const maxDuration = 300;
const args = ["-i", input, "-c:v", "libx264", "-preset", "veryfast", "-crf", "23",
"-c:a", "aac", "-movflags", "+faststart", output];{
"functions": {
"api/render.js": { "maxDuration": 300 }
}
}Skip the binary
Or answer in under a second: ?wait=0 and a webhook
Move the encode off the function. POST /v1/ffmpeg?wait=0 returns 202 with the job straight away, and a webhook_url gets the finished job POSTed to your app, so the function's run time no longer depends on the clip. We sent these args with a webhook_url: the API answered 202 in under a second, the job finished about 27 seconds later, and the webhook arrived on the first attempt with the out.mp4 link.
Check the Reelsdk-Signature header in a second route, as shown in ffmpeg on Vercel and the webhook docs; a failed delivery is retried, up to 6 attempts over about 7 h. A job can run up to 10 minutes, and compute is $0.02 per minute, billed per second, so this one cost under a cent.
// app/api/render/route.ts
export async function POST(request: Request) {
const { video } = await request.json();
const origin = new URL(request.url).origin;
const res = await fetch("https://api.reelsdk.com/v1/ffmpeg?wait=0", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.REELSDK_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
inputs: { "in.mp4": video },
args: ["-i", "in.mp4", "-c:v", "libx264", "-crf", "23", "-c:a", "aac", "-movflags", "+faststart", "out.mp4"],
outputs: ["out.mp4"],
webhook_url: `${origin}/api/reelsdk-webhook`,
}),
});
const { job } = await res.json();
return Response.json({ id: job.id, status: job.status }, { status: 202 });
}What a cut-off encode leaves behind
To see what a stopped encode leaves, we ran the same command on one core under timeout -s KILL 30. ffmpeg died with exit code 137 after 30 seconds, about a third of the way through. ffprobe could not open the file: moov atom not found, because an MP4 gets its index only when ffmpeg finishes.
So a timeout does not give you a shorter video, it gives you nothing, and the work done so far is lost. Retrying the same request on the same plan fails the same way, which is why the webhook route above beats a retry loop.
FAQ
Questions, answered
What is the maximum duration of a Vercel function?
With fluid compute, 300 s on Hobby, which is also the default. Pro and Enterprise default to 300 s and allow up to 800 s, and up to 1800 s per function in the extended beta.
Does streaming the response keep the function alive longer?
No. The max duration covers the whole invocation, streamed responses included, and Vercel terminates the function when it is reached.
Why ?wait=0 and not a long wait?
?wait= can hold the request for up to 300 s, the whole Hobby limit, so a long render would still time out the function. ?wait=0 returns 202 at once and the webhook brings the finished job. For renders you know are short, a wait inside your maxDuration works too.
Can I recover the partial MP4 after a timeout?
Not with ffmpeg alone. The file stops without its moov index, so players and ffprobe refuse it. Write fragmented MP4 if you need partial output, or move the encode out of the function.
- Vercel FunctionsVercel Functions cap bodies at 4.5 MB and bundles at 250 MB. Upload to Vercel Blob, send the URL and your ffmpeg arguments to ReelSDK from a route handler, get an mp4 link back. $0.02 per compute minute.
- moov atom not foundThe MP4's index is missing, usually because the file was cut off. Re-fetch it, repair it with untrunc, or move the moov first.
- Error: spawn ffmpeg ENOENTNode cannot find an ffmpeg program on PATH. Install it, spawn the ffmpeg-static path, or send the same args to an API.
- Netlify FunctionsNetlify Functions stop at 60 s and buffer at most 6 MB. Start a ReelSDK render with a 50 s wait, get the mp4 link in the same call, and catch longer jobs on a signed webhook stored in Netlify Blobs. $0.03 per output minute.
- AWS LambdaAWS Lambda caps a function and its layers at 250 MB unzipped and runs for 900 s at most. Send your ffmpeg arguments to ReelSDK from a Node handler and get the files back by webhook. $0.02 per compute minute.
- Cloudflare WorkersWorkers can't spawn ffmpeg and every isolate stops at 128 MB. Start a ReelSDK render from your Worker with one fetch and stream the finished mp4 into R2 from a signed webhook. Shorts are $0.30 up to 60 s.
- Compress a video with ffmpegShrink a video with ffmpeg: CRF 28 in x264 or x265, a smaller frame or a slower preset, with the size and quality each one gets you.
- ReelSDK vs self-hosted FFmpegTranscoding a minute of 1080p to 720p takes about 24 seconds of compute: about 0.8 cents on ReelSDK, about a tenth of a cent on a busy 4 vCPU box. Below about 11,000 minutes a month, the API costs less than an always-on box.
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
