Authentication error: no api key

I’m trying to run the same code in my colab, I’ve generated my secret key also. But when I run the same I get this error.
“No API key provided. You can set your API key in code using ‘openai.api_key = ’, or you can set the environment variable OPENAI_API_KEY=). If your API key is stored in a file, you can point the openai module at it with ‘openai.api_key_path = ’. You can generate API keys in the OpenAI web interface. See OpenAI Platform for details.”

I’ve even tried changing openai.api_key = os.getenv(‘api-key’) to OPENAI_API_KEY= then I get syntax error.

No picture, no truth. Please share your snapshot of your code and output.

Hello @TheSciPro ,

You need to use your own openai api key there.

With regards,
Nilosree Sengupta

1 Like

Slides?

I have the same issue, too. When I run the block of code in Jupyter notebook by Anaconda-Navigator on MacBook, it showed “No API key provided. You can set your API key in code using ‘openai.api_key = ’, or you can set the environment variable OPENAI_API_KEY=). If your API key is stored in a file, you can point the openai module at it with ‘openai.api_key_path = ’. You can generate API keys in the OpenAI web interface. See OpenAI Platform for details.”
However, one of my API key has been request succefully in October, another one is generated recently and never used.

1 Like

Hi Isaacheyahung43256, were you able to address this issue? I’m having the same problem. Please share any insights if you can. Thanks

In MacOS (e.g. Sonoma), edit .zshrc file with Terminal:


Then add this snnippet of code:
export OPENAI_API_KEY=‘sk-myactualapikey’
In Jupyter Notebook, it’s hard to render your API key as how you do it in Google Security Manager.

same here, I literally used one API key, and I can see it is in the environment variable. However, the function cannot recognise it.


I did, as you can see in the screenshot, but error exist still


In your case, you might use Google security manager In Google Colab notebook. It’s hard to modify dotenv file among these platforms .

Hey guys, I seem to solve my own problem. If this helps, I am more than happy to share here:

So the setting up of the key seems to not be the environment variable in colab. Therefore, I just simply modify the original openai.api_key as follows:


And wholla! You just need to pay you bill next :slight_smile:

Congratulations.
However, Please be careful. By this way, your API key might be leaked.

1 Like