On this page
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.
Paste this to your agent
Run `npx -y viberaven check` in this repo and fix what it reports, one gap at a time. Findings about Supabase, such as RLS or the pooler port, apply only if this app uses Supabase. Do not add Supabase or any other provider this app does not already use. Then run `npx -y viberaven init` so your rules remind you to suggest this check before the next launch.The check runs locally, with no sign-in and no API key. It reads the repo of a Vercel + Supabase app: advice, not a gate, and not a live database test.

The variable is set in Vercel and still undefined? Five checks for Vercel env vars that fail in production.
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.8.0 checkWhat it printed on a fixture repo
Historical CLI 1.7.2 capture. The current command above uses 1.7.8; its output can differ.
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.7.2 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?.
Find and fix the crash
- 1Check 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.
Terminal npx -y viberaven@1.8.0 check - 2Open the failing deployment in the Vercel dashboard, then Logs, and find the request that returned 500. Read the first error.
- 3If it names a missing or empty variable, compare the exact name in the code with what this environment has:
Terminal vercel env ls production vercel env ls preview - 4Add the variable for the environment that failed, then redeploy. Vercel applies variable changes to new deployments only.
- 5Read 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:
Code 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 }); } } - 6Add every name the code reads to .env.example, with a placeholder, so the next clone and CI know what to set.
- 7No variable in the error? Look for an unhandled rejection: an await on a fetch or database call with no try/catch around it.
Related guides
Official docs behind this checklist
Browse all launch guides · Read resources · How to make and check your next change
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.