All guidesVercel and env vars
On this page

Vercel question

Vercel

Vercel "This Serverless Function has crashed": what FUNCTION_INVOCATION_FAILED means and how to fix it

By Ohad Krispin, founder of VibeRaven · LinkedIn

"This Serverless Function has crashed" with 500: INTERNAL_SERVER_ERROR and Code: FUNCTION_INVOCATION_FAILED means the process running your Vercel function crashed, on an uncaught exception or an unhandled promise rejection. In an AI-built app, check first for a variable the code reads that is not set for the environment that built the deployment, such as an OpenAI API key: set it in Vercel for that environment and redeploy. The error page does not name the cause, so open the deployment's Logs tab and read the first error for that request; Vercel's troubleshooting steps also say to check the environment variables.

Terminal output of npx viberaven check on a Next.js fixture repo whose chat route reads OPENAI_API_KEY and OPENAI_MODEL, warning that .env.example documents neither.
Terminal output of npx viberaven check on a Next.js fixture repo whose chat route reads OPENAI_API_KEY and OPENAI_MODEL, warning that .env.example documents neither.

Repository check

Check this in your repo

Check your repo for env vars the code reads but never documents

From your app folder, with Node.js 20 or newer, run the command below. It compares the variable names your code reads (process.env, import.meta.env, Deno.env.get) with the names in .env.example and your other env templates, and reports each name no template lists as env_var_drift, a warning. It compares names only and cannot see which variables are set in your Vercel project.

Built for Vercel + Supabase apps, it is advice, not a gate. It is a repository check, not a live database test: it does not read your function logs or find the exception behind a 500. It exits with code 1 only when it finds a blocker, and writes a .viberaven folder that it does not add to .gitignore.

npx -y viberaven@1.6.12 check

What it printed on a fixture repo

On 2026-10-23 we ran it on a small Next.js fixture repo made for this page, not a customer repo. Its app/api/chat/route.ts creates an OpenAI client with process.env.OPENAI_API_KEY and reads process.env.OPENAI_MODEL, and its .env.example lists only NEXT_PUBLIC_SITE_URL. The output is below, with the temp folder shortened to ~/chat-app. A warning is not a blocker, so the exit code was 0.

$ npx -y viberaven@1.6.12 check

viberaven check · ~/chat-app

🟡 Env vars used in code but missing from .env.example  (env_var_drift)
   Code reads 2 environment variables that .env.example does not document (OPENAI_API_KEY, OPENAI_MODEL). Fresh clones, CI, and the production deploy can silently run without them.

Verdict: ✅ no blockers, 1 warning · score 90
Fix: viberaven fix · Details: ~/chat-app/.viberaven/agent-tasklist.md

Where is the real error behind 500 FUNCTION_INVOCATION_FAILED?

In the function's logs. Vercel says they are under the Logs tab of the deployment: filter to the request that failed and read the first error and its stack trace, not the last line. A missing credential looks like this; with openai 5.23.0, creating a client while OPENAI_API_KEY is unset threw this in a local run on 2026-10-23:

OpenAIError: Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.

FUNCTION_INVOCATION_FAILED vs FUNCTION_INVOCATION_TIMEOUT

FUNCTION_INVOCATION_FAILED is a 500: the process crashed. FUNCTION_INVOCATION_TIMEOUT is a 504: the function ran past its maximum duration, often while it waited on a slow model call. See Why does my Vercel function time out with FUNCTION_INVOCATION_TIMEOUT?.

Checklist

Find and fix the crash

  1. 01Open the failing deployment in the Vercel dashboard, then Logs, and find the request that returned 500. Read the first error.
  2. 02
    If it names a missing or empty variable, compare the exact name in the code with what this environment has:
    vercel env ls production
    vercel env ls preview
  3. 03Add the variable for the environment that failed, then redeploy. Vercel applies variable changes to new deployments only.
  4. 04
    Read the key inside the handler and fail with a clear message, and catch errors from the model call, so one missing value returns an error you can read instead of crashing the process. Vercel suggests a try/catch block:
    export async function POST(request: Request) {
      const apiKey = process.env.OPENAI_API_KEY;
      if (!apiKey) return Response.json({ error: 'OPENAI_API_KEY is not set' }, { status: 500 });
      try {
        // create the client and call the model here
      } catch (error) {
        console.error(error);
        return Response.json({ error: 'Model call failed' }, { status: 502 });
      }
    }
  5. 05Add every name the code reads to .env.example, with a placeholder, so the next clone and CI know what to set.
  6. 06No variable in the error? Look for an unhandled rejection: an await on a fetch or database call with no try/catch around it.

Related

Sources

Official docs behind this checklist

FAQ

FAQ for builders before launch

Does FUNCTION_INVOCATION_FAILED mean Vercel is down?

Vercel describes it as a failed invocation, caused by an error in the function itself or an issue with the environment it runs in. Start with your own logs; they show the exception from your code.

Does one crash take down other requests?

With fluid compute, Vercel says an uncaught exception or unhandled rejection is logged and current requests on the same instance finish before the process stops.