import os
import openai
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env file
openai.api_key = os.environ['OPEN_API_KEY']
Above command throws the error mentioned below:-
KeyError Traceback (most recent call last)
Cell In[22], line 6
4 from dotenv import load_dotenv, find_dotenv
5 _ = load_dotenv(find_dotenv()) # read local .env file
----> 6 openai.api_key = os.environ[‘OPEN_API_KEY’]
File /usr/local/lib/python3.9/os.py:679, in _Environ.getitem(self, key)
676 value = self._data[self.encodekey(key)]
677 except KeyError:
678 # raise KeyError with the original key value
→ 679 raise KeyError(key) from None
680 return self.decodevalue(value)
KeyError:
Note:- We have replaced the OPEN_API_KEY with correct key value