Trying to use OpenAI in #javascriptmas

Hello! I tried to use OpenAI to generate a response for the challenge today, and I even used Scrimba env to save my API token but I still get this error:
Error: It looks like you're running in a browser-like environment. This is disabled by default, as it risks exposing your secret API credentials to attackers. If you understand the risks and have appropriate mitigations in place, you can set the dangerouslyAllowBrowseroption totrue, e.g., new OpenAI({ apiKey, dangerouslyAllowBrowser: true }); https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety

Is there something I’m missing?

1 Like

Hi
I don’t know about the challenge.
But one of the first lessons in the the AI Engineering pathway course talks about this
(link if you can/want to enrol just to view that lesson)

Here’s what is placed in the code throughout the rest of the course (line 1 to 5):

1 Like

But if I do that, if I share my note online, will people be able to print out the api key just like you demonstrated in the code snippet? Is there a way to use openAPI with the env variables so the api key is not exposed?

I’m new to this so don’t know quite how Scrimba interface works, but it seems to get the key automatically from my Environmental variable.

I just created a completely new Scrim. Added the dependency “openai@4.14.2”. then just with the code shown it could console.log the key

I think I remember someone saying if you fork the scrim, your api key still works via env var, and they can’t access it unless you console.log it. I know someone else was having an issue with the api key not working in env vars if they opened a browser window incognito. I think Scrimba will be lenient on this one.

Tom said this in Discord:

“When we check a scrim to see if a challange has been completed before awarding a prize, we use our own API keys so quote limits/credit won’t matter :slightly_smiling_face: