Issue with Accessing Environment Variables on Vercel Deployment

Current vs Expected Behavior:
I’m deploying a chatbot project on Vercel that uses API keys stored in environment variables (specifically MISTRAL_API_KEY). When I run the project locally using a .env file, everything works perfectly, and the API key is accessed correctly. However, after deploying it on Vercel, the environment variables are not being accessed as expected, causing API calls to fail.

I’ve added the environment variables to the Vercel dashboard under Project Settings > Environment Variables, but my code still seems to be unable to access them after redeployment.

Code, Configuration, and Steps to Reproduce:
Locally, I’m using a .env file and accessing environment variables like this:

const apiKey = process.env.MISTRAL_API_KEY;

On Vercel, I set the MISTRAL_API_KEY in Environment Variables for the correct environment (Production) and redeployed the project.
Despite this, the key is undefined during runtime on Vercel.The Tech stack for this project is html,css and js

Hi, @ahsentahir! Welcome to the Vercel Community.

Could you share a minimal reproducible example with us to dig a bit deeper here?

Otherwise, some troubleshooting steps I’d recommend are:

  1. Double-check that the environment variable is correctly set in the Vercel dashboard under Project Settings > Environment Variables.
  2. Ensure the variable name matches exactly (MISTRAL_API_KEY in this case) and that it’s set for the correct environment (Production).
  3. After adding or modifying environment variables in the Vercel dashboard, make sure to redeploy the project for the changes to take effect.
  4. Ensure that the files accessing the environment variables have the correct permissions.

Let us know how you get on!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.