openai-python: import openai openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)
Describe the bug
[ERROR][2023-03-04 18:25:20][chat_gpt_bot.py:68] - Invalid URL (POST /v1/chat/completions) Traceback (most recent call last): File “/opt/chatgpt-on-wechat/bot/chatgpt/chat_gpt_bot.py”, line 44, in reply_text response = openai.ChatCompletion.create( File “/usr/local/lib/python3.9/site-packages/openai/api_resources/chat_completion.py”, line 25, in create return super().create(*args, **kwargs) File “/usr/local/lib/python3.9/site-packages/openai/api_resources/abstract/engine_api_resource.py”, line 153, in create response, _, api_key = requestor.request( File “/usr/local/lib/python3.9/site-packages/openai/api_requestor.py”, line 226, in request resp, got_stream = self._interpret_response(result, stream) File “/usr/local/lib/python3.9/site-packages/openai/api_requestor.py”, line 619, in _interpret_response self._interpret_response_line( File “/usr/local/lib/python3.9/site-packages/openai/api_requestor.py”, line 679, in _interpret_response_line raise self.handle_error_response( openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)
To Reproduce
response = openai.ChatCompletion.create(
openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)
Code snippets
response = openai.ChatCompletion.create(
openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)
[root@vps87388579 chatgpt-on-wechat]# pip3 show openai
Name: openai
Version: 0.27.0
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: support@openai.com
License: None
Location: /usr/local/lib/python3.9/site-packages
Requires: requests, aiohttp, tqdm
Required-by:
OS
centos 8.6
Python version
3.9
Library version
0.27
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 15
You should change from
openai.Completion.createtoopenai.ChatCompletion.create.I was able to fix it by updating the openai lib.
pip install --upgrade openai.
Then you can try this:
I got the answer in the official documentation:
https://openai.com/blog/introducing-chatgpt-and-whisper-apis
This error is expected if using
openai.Completion.createwith a chat model. Please useopenai.ChatCompletion.createinstead. This includesgpt-3.5-turboandgpt-4(for those with access).This seems to be account related. Some accounts are affected while others are not.
I think they moved the endpoint for the new models. They also seemed to have updated the error…
openai.error.InvalidRequestError: This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
So the maybe the API needs to add ‘/chat’ for gpt-3.5-turbo and gpt-3.5-turbo-0301 models? The documentation looks like only those two are supported for ‘chat completion’ but doesn’t state that they are losing the normal endpoint. So 🤷🏻♀️
https://platform.openai.com/docs/api-reference/chat/create
I’ve upgraded via pip and still get the same error.
same issue in my case I have a loop that calls the api multiple times, bit backoff retry exception handling, and It only does it a few times, in the loop, but not on every one and it seems very unpredictable