openai-python: openai.error.AuthenticationError:
Describe the bug
Since yesterday 24.05.2023 around your outage I am facing this errors:
..
File "/opt/homebrew/lib/python3.10/site-packages/openai/api_resources/embedding.py", line 33, in create
response = super().create(*args, **kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
File "/opt/homebrew/lib/python3.10/site-packages/openai/api_requestor.py", line 230, in request
resp, got_stream = self._interpret_response(result, stream)
File "/opt/homebrew/lib/python3.10/site-packages/openai/api_requestor.py", line 624, in _interpret_response
self._interpret_response_line(
File "/opt/homebrew/lib/python3.10/site-packages/openai/api_requestor.py", line 687, in _interpret_response_line
raise self.handle_error_response(
openai.error.AuthenticationError: <empty message>
I tried several approaches, thought LangChain would be the problem, thought a vectorstore is it, but now I think it must be something with the API as I rebuilt with several options and it all leads to the same error.
To Reproduce
openai.api_key = OPENAI_KEY or os.getenv("OPENAI_API_KEY")
# where texts can be a list of strings like
texts = ["test", "foo"]
for i in texts:
response = openai.Embedding.create(
input=i,
model="text-embedding-ada-002"
)
embeddings = response['data'][0]['embedding']
Code snippets
No response
OS
macOS, m1-chip
Python version
Python 3.10.9
Library version
openai==0.27.7
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 14
- Comments: 42 (5 by maintainers)
This problem has been bothering me for a week.
Finally, I found out that when you pass your openai-api-key to a public space(such as github), your openai-api-key on the OpenAI website(https://platform.openai.com/account/api-keys) will be automatically deleted, and then you will have this error report.
So you must regenerate a key and ensure that it is not transferred to the public space.
can you try the solution in this order?
1- open .env file (in project root directory) & add OPENAI_API_KEY
OPENAI_API_KEY=sk-....2- implement this lines in your python file:
3- call langchain method (implicitly openai method)
I saw that LangChain read the wrong key from os’s environment value
i had this problem. When i checked my API key on platform.openai.com, it had disappeared. I know i havent deleted it, but suddenly it had been lost. So i just created a new API key and continued using without problems. Hope this will also solve you problems guys ))
In our case, we generated another token, and that fixed the issue
@mehmetkoca thank you! Your solution works for me! I still don’t know, why my old code stopped working, but I’m just glad, it works now:)
Actually, that might not help. Could we instead ask for more debugging information? The Authentication Error should have more details. Something like this as a wrapper around your code might do the trick:
LangChain uses the OpenAI Python SDK so that’s the main issue. I had as described problems with several libraries.