Vercel question
Vercel "This Serverless Function has crashed": what FUNCTION_INVOCATION_FAILED means and how to fix it
"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.

The variable is set in Vercel and still undefined? Five checks for Vercel env vars that fail in production.
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 checkWhat 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.mdWhere 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
- 01Open the failing deployment in the Vercel dashboard, then Logs, and find the request that returned 500. Read the first error.
- 02If 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 - 03Add the variable for the environment that failed, then redeploy. Vercel applies variable changes to new deployments only.
- 04Read 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 }); } } - 05Add every name the code reads to .env.example, with a placeholder, so the next clone and CI know what to set.
- 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
Related guides
Sources
Official docs behind this checklist
Browse all launch guides · Read resources · How to make and check your next change
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.