[Solved] openai.ChatCompletion no longer supported in openai>=1.0.0

[Solved] openai.ChatCompletion no longer supported in openai>=1.0.0

Are you getting the following error while executing openai API?

Traceback (most recent call last):
  File "/Users/csestack/code/openapitest.py", line 17, in <module>
    response = get_completion(prompt)
  File "/Users/csestack/code/openapitest.py", line 9, in get_completion
    response = openai.ChatCompletion.create(
  File "/opt/homebrew/lib/python3.11/site-packages/openai/lib/_old_api.py", line 39, in __call__
    raise APIRemovedInV1(symbol=self._symbol)

You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. 

Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`

A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742


You are getting this error mostly as you are using the old version code with the new openai Python module version >=1.0.0. The code you have written is no longer supported with the new openai version.

Here method openai.ChatCompletion() no longer supported with the latest openai version.

There are a couple of solutions you have to solve this problem.

1. Upgrade your code to use the new openai API

You need to update your code to use the new openai API. Follow this guide to migrate your code provided by openai version 1.0.0.

2. Downgrade your openai Python module version

If you are confident about your code and don’t want to change it, downgrade your Python openai module to the supported version.

For example, you can use openai version 0.28. Install it using the pip command and it will solve your problem.

pip install openai==0.28

Take note: Using an older openai version (openai==0.28) is safe. But this is a temporary solution and you may need to upgrade to the newer version in the future.

You are free to use any of the solutions I have provided you. Choose the option best for your needs and adopt the change. If you still have confusion or any query feel free to ask.

Leave a Reply

Your email address will not be published. Required fields are marked *