I'm struggling to understand how to use Netlify environment variables in my Vite app deployment. I get this error
The API key is stored in Netlify here:
And my code is here:
I've read Netlify's docs, search the internet and tried AI. I just can't figure it out.
Can anyone save me?
Thanks
Rich
Your first and second images show the problem: your build is looking for $OPENAI_API_KEY and you've set $VITE_APP_OPENAI instead. The names need to match exactly :)
One trick I like to use to debug environment variables is to prepend my build command with env &&
since that will list all variables before starting your build (though not before dependency installation, in case you need that to install npm modules during the first stage of the Netlify build).