OPENAI API KEY Error

import OpenAI from ‘openai’;

// OpenAI config
export const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
dangerouslyAllowBrowser: true
});

console.log(process.env.OPENAI_API_KEY)

/**

  • Challenge:
    1. Ask OpenAI to explain something complicated
  • to you. For example Quantum Computing.
  • Prompt Engineering Stretch Goals
    • See if you can control the level of complexity of
  • the generated content, for example is this for
  • 10-year-olds or college kids?
    • See if you can control the length of the output.
  • **/

I have used openai api keys for 2 years in various platforms, but it is not working for this.

I do not get any response.

1 Like

1 Like

Hey @Love, is you hardcode your API key rather than environment variables, is the issue still popping up? Not a good way to do this but just debugging for this case.

1 Like

1 Like

@roku This issue occurs with this course as well. What do you mean by saying my API key is hardcoded? I placed the key in the environment.

Thank you for your assistance.

1 Like

Hm, that replace error might be another issue…

But something to try - when I’m referring to hardcoding I mean to write the API key straight within the code rather than the environment variable. As stated, this shouldn’t be done in live production but only for debugging.

1 Like

@roku No, I did not hardcode, but only put the key in the environment. Could you help me with replace error? I think it’s not about the openai api key error I initially thought, but it has errors with other courses too whenever I do the first run. After I try to run again, it does not give any output at all.

1 Like

Also, could you please expand my subscription days? I paid it, but I have not been able to use it effectively and make progress due to the issue.

1 Like

Sure could you please let me know what your Scrimba account URL is?

Could you also let me know what browser and device you’re using? While the team is looking into this we can do some different browser tests to see if that could be the issue with this specific one.

@roku Hi Roku, I DM’d you yesterday. Please check when you have a moment. Thank you for your assistance.

Hey @Love, was this a message on Discord? Been chatting to a bunch of users recently on Discord so just double checking if I’ve replied to you on that already.

Screenshot 2025-01-25 at 9.45.00 AM

@roku If you click my profile, you will see a chat button. I dm’d you there.

Ah weird, didn’t get any notifications from this chat. Found it now, will chat to you there.