I create a ChatGPT key and paste it in the space of the code which is for the api key. However, when I run the code, even in VSCode or in the jupyter notebook from the class, it has an error which says no api key provideed. What can I do to solve that problem? How do I write that api key?
Please see this similar thread, it might help you. Hopefully you can access the ChatGPT course discussions.
Also, @sebasca9, just to make sure itâs clear - for this course you do not have to create your own key if you use the notebook in the course. You can just use the key thatâs provided for you and is set automatically when you run this code:
import openai
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai.api_key = os.getenv('OPENAI_API_KEY')
I am trying to write on my own local computer. Itâs showing api key is not provided. How can I fix it?
Youâll need to purchase your own API key from OpenAI.
I have created the api key in chatgpt and assigned as told in the course. will i have to purchase it then it will work?
Sorry, I am not a mentor for this course, so someone else will have to answer that.
Hi,
Perhaps the confusion comes from this line:
openai.api_key = os.getenv(âOPENAI_API_KEYâ)
That reads the KEY from the âenvironmentâ, typically a file in your working folder named â.envâ, there is a simpler way to this â
After you have a key, either from free trial or purchased, just replace the line
openai.api_key = os.getenv(âOPENAI_API_KEYâ) with
openai.api_key = âYOUR_ OPENAI_API_KEYâ
But, be aware of not to share your code, since the KEY can be copied and used by anyone how has access to it.
Hope it helps,
I tried this but when we change openai.api_key = os.getenv(âOPENAI_API_KEYâ)
with openai.api_key = âYOUR_ OPENAI_API_KEYâ
it gives syntax error