I am trying to deploy a FastAPI application on Vercel, but I am having trouble getting environment variables to load. My setup works perfectly fine locally, where I use python-dotenv with load_dotenv() to load the .env file, but on Vercel, the environment variables are not being found at runtime.
Here are the steps I've taken so far:
- Added environment variables in the Vercel dashboard under Settings > Environment Variables.
- Verified that the app works locally with the same .env file using load_dotenv().
- Deployed the app to Vercel, but it fails to find the environment variables.
- Tried changing the Vercel Node.js version to 18.x (based on suggestions from other threads), but this caused my application to stop working entirely.
Additional Details:
- My application uses Python 3.11 and FastAPI.
- My environment variables include SECRET_KEY and DATABASE_URL.
Questions:
- Is there a specific configuration required to make Python-based apps load environment variables correctly on Vercel?
- Does Vercel require a particular runtime configuration to support Python 3.11 and environment variables together?
- Has anyone successfully run a FastAPI app on Vercel with environment variables recently?
Any guidance or examples would be greatly appreciated!
Thank you in advance for your help.