Vercel FUNCTION_INVOCATION_TIMEOUT (504) on API routes or AI calls

Vercel API route times out with 504 FUNCTION_INVOCATION_TIMEOUT? Common with slow AI calls. Raise maxDuration, stream, or move work to background.

Reviewed October 14, 2026

What it means in plain English

Your server function took longer than it's allowed to run, so Vercel stopped it. Long AI responses and slow database queries are the usual culprits.

Likely causes

  • Waiting for a full AI completion before responding.
  • Slow external API or database (e.g. connecting from far away).
  • Function never sends a response (missing return).

How to fix it, step by step

  1. Check Vercel → Logs to see which route times out.
  2. Raise the limit for that route in vercel.json (within your plan; with Fluid compute Hobby allows up to 300s, and Pro and Enterprise allow up to 800s, or 1800s in beta on supported Node.js, Bun, and Python runtimes — anything over 800s has to be set on that function, not as the project default):
{ "functions": { "app/api/chat/route.ts": { "maxDuration": 120 } } }

In Next.js you can also export export const maxDuration = 120 from the route. 3. Stream AI responses instead of waiting for the whole thing. 4. Move long jobs to a background queue and return immediately. 5. Make sure every code path returns a response.

How to check it worked

  • Call the route again; it completes or streams without 504.
  • Logs show the duration under the limit.

Sources

Can't fix it? Get help.

If the steps didn't clear the error, send what the screen says. A person can take a look. This is a request for a paid fix, not an instant chat.

Request a fix