# Authentication error: no api key

**URL:** <https://community.deeplearning.ai/t/authentication-error-no-api-key/401822>\
**Category:** ChatGPT Prompt Engineering for Developers\
**Created:** [July 30, 2023, 5:50am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822 "2023-07-30T05:50:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheSciPro](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@TheSciPro](https://community.deeplearning.ai/u/TheSciPro)\
**Post date:** [July 30, 2023, 5:50am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/1 "2023-07-30T05:50:23Z")

</div>

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](https://platform.openai.com/account/api-keys) for details.”

I’ve even tried changing openai.api\_key = os.getenv(‘api-key’) to OPENAI\_API\_KEY= then I get syntax error.

---

<div class="post-metadata">

**Author:** ![klchang](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@klchang](https://community.deeplearning.ai/u/klchang)\
**Post date:** [July 30, 2023, 10:47pm UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/2 "2023-07-30T22:47:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nilosreesengupta](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nilosreesengupta/32/11457_2.png) [@nilosreesengupta](https://community.deeplearning.ai/u/nilosreesengupta)\
**Post date:** [July 31, 2023, 9:31am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/3 "2023-07-31T09:31:08Z")

</div>

Hello @TheSciPro ,

You need to use your own openai api key there.

With regards,  
Nilosree Sengupta

---

<div class="post-metadata">

**Author:** ![adeel\_sahi](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@adeel\_sahi](https://community.deeplearning.ai/u/adeel_sahi)\
**Post date:** [August 4, 2023, 5:04pm UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/4 "2023-08-04T17:04:11Z")

</div>

Slides?

---

<div class="post-metadata">

**Author:** ![Isaacheyahung43256](https://avatars.discourse-cdn.com/v4/letter/i/ba8739/32.png) [@Isaacheyahung43256](https://community.deeplearning.ai/u/Isaacheyahung43256)\
**Post date:** [November 9, 2023, 4:13pm UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/5 "2023-11-09T16:13:42Z")

</div>

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](https://platform.openai.com/account/api-keys) for details.”  
However, one of my API key has been request succefully in October, another one is generated recently and never used.

 ![Screenshot 2023-11-10 at 12.10.09 AM](https://global.discourse-cdn.com/dlai/original/3X/f/0/f0d5c5cfee1c4fcc1327fb39e82779455ae4ef7a.png)

---

<div class="post-metadata">

**Author:** ![Milvi](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Milvi](https://community.deeplearning.ai/u/Milvi)\
**Post date:** [November 29, 2023, 5:19pm UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/6 "2023-11-29T17:19:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Isaacheyahung43256](https://avatars.discourse-cdn.com/v4/letter/i/ba8739/32.png) [@Isaacheyahung43256](https://community.deeplearning.ai/u/Isaacheyahung43256)\
**Post date:** [December 2, 2023, 12:10am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/7 "2023-12-02T00:10:34Z")

</div>

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

 ![Screenshot 2023-12-02 at 8.09.50 AM](https://global.discourse-cdn.com/dlai/original/3X/c/e/cedf7a94d6ec9d4bb160a40110ec46c53d1bcc6a.png)  
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.

---

<div class="post-metadata">

**Author:** ![Jimmy0Jimmy](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jimmy0jimmy/32/77681_2.png) [@Jimmy0Jimmy](https://community.deeplearning.ai/u/Jimmy0Jimmy)\
**Post date:** [December 9, 2023, 1:39am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/8 "2023-12-09T01:39:39Z")

</div>

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

 ![Screenshot 2023-12-09 at 12.34.27](https://global.discourse-cdn.com/dlai/original/3X/f/5/f5d484a562d0430d3156ea2b71532fd3bc00b4a9.png)  
 ![Screenshot 2023-12-09 at 12.34.43](https://global.discourse-cdn.com/dlai/original/3X/a/b/abce051032f21ed2be0569d6909e8660ec8b15d0.jpeg)

---

<div class="post-metadata">

**Author:** ![Jimmy0Jimmy](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jimmy0jimmy/32/77681_2.png) [@Jimmy0Jimmy](https://community.deeplearning.ai/u/Jimmy0Jimmy)\
**Post date:** [December 9, 2023, 1:42am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/9 "2023-12-09T01:42:12Z")

</div>

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

 ![Screenshot 2023-12-09 at 12.34.43](https://global.discourse-cdn.com/dlai/original/3X/a/b/abce051032f21ed2be0569d6909e8660ec8b15d0.jpeg)  
 ![Screenshot 2023-12-09 at 12.34.27](https://global.discourse-cdn.com/dlai/original/3X/f/5/f5d484a562d0430d3156ea2b71532fd3bc00b4a9.png)

---

<div class="post-metadata">

**Author:** ![Isaacheyahung43256](https://avatars.discourse-cdn.com/v4/letter/i/ba8739/32.png) [@Isaacheyahung43256](https://community.deeplearning.ai/u/Isaacheyahung43256)\
**Post date:** [December 9, 2023, 1:57am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/10 "2023-12-09T01:57:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jimmy0Jimmy](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jimmy0jimmy/32/77681_2.png) [@Jimmy0Jimmy](https://community.deeplearning.ai/u/Jimmy0Jimmy)\
**Post date:** [December 9, 2023, 2:01am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/11 "2023-12-09T02:01:39Z")

</div>

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:

 ![Screenshot 2023-12-09 at 13.00.28](https://global.discourse-cdn.com/dlai/original/3X/8/9/89b4b162fafb000f985ad2f1a3e47aef4b39c011.png)  
And wholla! You just need to pay you bill next 🙂  
 ![Screenshot 2023-12-09 at 13.01.15](https://global.discourse-cdn.com/dlai/original/3X/9/5/95c17204e13d2d5dc9c5e53f6567453df20f9fd3.png)

---

<div class="post-metadata">

**Author:** ![Isaacheyahung43256](https://avatars.discourse-cdn.com/v4/letter/i/ba8739/32.png) [@Isaacheyahung43256](https://community.deeplearning.ai/u/Isaacheyahung43256)\
**Post date:** [December 9, 2023, 2:04am UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/12 "2023-12-09T02:04:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![markazi2](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@markazi2](https://community.deeplearning.ai/u/markazi2)\
**Post date:** [March 26, 2024, 4:57pm UTC](https://community.deeplearning.ai/t/authentication-error-no-api-key/401822/13 "2024-03-26T16:57:21Z")

</div>

Thanks, this helped me. Were you able to do anything after apparently hitting the billing quota?
