πŸ”§ Error Fixes
Β· 1 min read

Vercel: Serverless Function Timeout β€” How to Fix It


FUNCTION_INVOCATION_TIMEOUT

Your Vercel serverless function exceeded the time limit (10s free, 60s pro).

Why this happens

Vercel serverless functions run in a Lambda-like environment with strict time limits. If your function does heavy computation, makes slow external API calls, or waits on an unresponsive database, it exceeds the timeout and Vercel kills it. The free tier limit of 10 seconds is especially tight.

Fix 1: Optimize the function

// ❌ Doing too much in one function
export async function GET() {
  const data = await heavyComputation();
  const processed = await processAll(data);
  await saveToDb(processed);
  return Response.json(processed);
}

// βœ… Break into smaller operations
export async function GET() {
  const data = await getCachedData();
  return Response.json(data);
}

Fix 2: Increase timeout (Pro plan)

// vercel.json
{
  "functions": {
    "api/heavy.ts": {
      "maxDuration": 60
    }
  }
}

Fix 3: Use background jobs

For long-running tasks, use a queue (Inngest, Trigger.dev, QStash) instead of doing everything in the request.

Alternative solutions

Move heavy work to Vercel Edge Functions (no cold start, 30s limit) or use streaming responses to keep the connection alive while processing:

export const runtime = 'edge';
export async function GET() {
  const stream = new ReadableStream({ /* ... */ });
  return new Response(stream);
}

Prevention

  • Add timeouts to all external API calls (fetch with AbortSignal.timeout(5000)) so one slow dependency doesn’t kill your function.
  • Cache expensive results with unstable_cache or a Redis layer to avoid recomputation.

Related: AWS Lambda Timeout fix Β· Cloudflare 524 Timeout fix Β· Vercel Build Failed fix Β· What is Vercel