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

Vercel's error reference: a Function error, HTTP 504, updated May 14, 2026. Not reproduced by us
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

Vercel's limits next to this encode
ItemValue
Hobby max duration300 s, also the default
Pro and Enterprise max duration800 s, or 1800 s per function in beta
Default function CPU1 vCPU with 2 GB
28 s clip, default preset, one coreAbout 87 s
Same clip, -preset veryfastAbout 41 s
Killed after 30 sA third of the frames, file unreadable
ReelSDK with ?wait=0202 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
// 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];
vercel.json
{
  "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.tsTry it
// 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 });
}
Sent with ?wait=0 and a webhook_url: the full 28 seconds at 1080x1920.Input: video.mp4

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.

Ready to build?

Ship video from your app today

Your first $0.50 is free, and one key covers every endpoint.

Moonlit lake with a lit cabin under the mountains