I’m trying to run an API call to OpenAI locally, and have setup my .env.local like this:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY= (my key here)
CLERK_SECRET_KEY= (my secret key here)
OPENAI_API_KEY= (my secret key here)
Weirdly, I can access my NEXT_PUBLIC and CLERK_SECRET normally and everything runs well locally. However, when I try to make an API request using a Server Action to OpenAI, it says that my API key is invalid and logs something like ‘sk-…yourapikey…’.
I tried logging it manually using console.log(process.env.OPENAI_API_KEY) and in fact it logs out as ‘sk-…yourapikey…’.
If I change it to NEXT_PUBLIC_OPENAI_API_KEY on my .env.local file it works, but that doesn’t seem like a suitable solution.
Keep in mind I’m trying to run this in a Server Action right under /app/actions/generate-image.ts
Also, when I deployed to Vercel and set the environment variables there, it always worked without needing the “NEXT_PUBLIC” prefix.
Any ideas? Thanks a lot!