# I am getting this error in jupyter even though i copied as it is in the guidlines

**URL:** <https://community.deeplearning.ai/t/i-am-getting-this-error-in-jupyter-even-though-i-copied-as-it-is-in-the-guidlines/408032>\
**Category:** ChatGPT Prompt Engineering for Developers\
**Created:** [August 4, 2023, 3:57pm UTC](https://community.deeplearning.ai/t/i-am-getting-this-error-in-jupyter-even-though-i-copied-as-it-is-in-the-guidlines/408032 "2023-08-04T15:57:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manikanta\_Maduri](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Manikanta\_Maduri](https://community.deeplearning.ai/u/Manikanta_Maduri)\
**Post date:** [August 4, 2023, 3:57pm UTC](https://community.deeplearning.ai/t/i-am-getting-this-error-in-jupyter-even-though-i-copied-as-it-is-in-the-guidlines/408032/1 "2023-08-04T15:57:09Z")

</div>

* * *

AuthenticationError Traceback (most recent call last)  
 in   
16 `{text}`  
17 “”"  
—\> 18 response = get\_completion(prompt)  
19 print(response)

in get\_completion(prompt, model)  
1 def get\_completion(prompt, model=“gpt-3.5-turbo”):  
2 messages = [{“role”: “user”, “content”: prompt}]  
----\> 3 response = openai.ChatCompletion.create(  
4 model=model,  
5 messages=messages,

~\anaconda3\lib\site-packages\openai\api\_resources\chat\_completion.py in create(cls, \*args, \*\*kwargs)  
23 while True:  
24 try:  
—\> 25 return super().create(\*args, \*\*kwargs)  
26 except TryAgain as e:  
27 if timeout is not None and time.time() \> start + timeout:

~\anaconda3\lib\site-packages\openai\api\_resources\abstract\engine\_api\_resource.py in create(cls, api\_key, api\_base, api\_type, request\_id, api\_version, organization, \*\*params)  
147 url,  
148 params,  
 → 149 ) = cls.\_\_prepare\_create\_request(  
150 api\_key, api\_base, api\_type, api\_version, organization, \*\*params  
151 )

~\anaconda3\lib\site-packages\openai\api\_resources\abstract\engine\_api\_resource.py in \_\_prepare\_create\_request(cls, api\_key, api\_base, api\_type, api\_version, organization, \*\*params)  
104 params[“timeout”] = MAX\_TIMEOUT  
105  
 → 106 requestor = api\_requestor.APIRequestor(  
107 api\_key,  
108 api\_base=api\_base,

~\anaconda3\lib\site-packages\openai\api\_requestor.py in **init** (self, key, api\_base, api\_type, api\_version, organization)  
136 ):  
137 self.api\_base = api\_base or openai.api\_base  
 → 138 self.api\_key = key or util.default\_api\_key()  
139 self.api\_type = (  
140 ApiType.from\_str(api\_type)

~\anaconda3\lib\site-packages\openai\util.py in default\_api\_key()  
184 return openai.api\_key  
185 else:  
 → 186 raise openai.error.AuthenticationError(  
187 “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 [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys) for details.”  
188 )

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

---

<div class="post-metadata">

**Author:** ![Manikanta\_Maduri](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Manikanta\_Maduri](https://community.deeplearning.ai/u/Manikanta_Maduri)\
**Post date:** [August 4, 2023, 3:58pm UTC](https://community.deeplearning.ai/t/i-am-getting-this-error-in-jupyter-even-though-i-copied-as-it-is-in-the-guidlines/408032/2 "2023-08-04T15:58:54Z")

</div>

This is my code:  
import openai  
import os

from dotenv import load\_dotenv, find\_dotenv  
\_ = load\_dotenv(find\_dotenv())

openai.api\_key = os.getenv(‘OPENAI\_API\_KEY’)

def get\_completion(prompt, model=“gpt-3.5-turbo”):  
messages = [{“role”: “user”, “content”: prompt}]  
response = openai.ChatCompletion.create(  
model=model,  
messages=messages,  
temperature=0, # this is the degree of randomness of the model’s output  
)  
return response.choices[0].message[“content”]

text = f"“”  
You should express what you want a model to do by \   
providing instructions that are as clear and \   
specific as you can possibly make them. \   
This will guide the model towards the desired output, \   
and reduce the chances of receiving irrelevant \   
or incorrect responses. Don’t confuse writing a \   
clear prompt with writing a short prompt. \   
In many cases, longer prompts provide more clarity \   
and context for the model, which can lead to \   
more detailed and relevant outputs.  
“”"  
prompt = f"“”  
Summarize the text delimited by triple backticks \   
into a single sentence.  
`{text}`  
“”"  
response = get\_completion(prompt)  
print(response)

---

<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:** [August 4, 2023, 11:28pm UTC](https://community.deeplearning.ai/t/i-am-getting-this-error-in-jupyter-even-though-i-copied-as-it-is-in-the-guidlines/408032/3 "2023-08-04T23:28:54Z")

</div>

The reason is as follows in your error info:

> [@Manikanta\_Maduri](#):
>
> AuthenticationError: No API key provided.

You need set your API key in code.
