"Missing environment variable" / API key not set: what to do
Secret settings such as API keys live outside your code, in environment variables. Your computer has them in a local file; the website host does not unless you add them there. The app asks for a value, finds nothing, and stops.
The error looks like this:
Error: Missing environment variable
How to fix it
- Find the exact name. The error or the code names the variable, for example
OPENAI_API_KEY. Copy the name exactly, including capital letters. - Add it where the app runs. On Vercel, open the project, go to its environment variables settings, add the name and value, and choose the environments it applies to (Production, Preview, Development).
- Redeploy. Vercel says changes to variables are not applied to earlier deployments, only new ones. Trigger a new deployment after saving.
- For local work, use a local file. Vercel lets you download the Development values with
vercel env pull, which writes a.envfile. Keep that file out of Git.
What you should see
The new deployment starts without the "missing" message, and the feature that needed the key works.
Not fixed? Bring the exact message to Bilo and we will look at it with you.
Still stuck? Paste your error into BiloQuick questions
Why does it work locally?
Your computer reads a local .env file that was never uploaded. Hosts do not see it, which is the point: secrets should not be in your code.
Can I paste the key into the code to test?
Please do not. Code often ends up in Git, where the key can leak. Use the host's variable settings instead.
I added it but nothing changed.
You probably have not redeployed, or you added it to a different environment than the one running (for example Preview instead of Production).
Sources and date checked
- Vercel: Environment variables: https://vercel.com/docs/environment-variables (checked 2026-11-01)
Written in our own words from the official pages above. Tool names are only references; we are not affiliated with them. Commands change between versions, so check the linked docs if something differs.