Error database

APIRemovedInV1: openai.ChatCompletion is no longer supported

The openai Python library changed its entire interface in v1.0. Rewrite the call with the client object — or run the automatic migration tool.

The message you saw
APIRemovedInV1: openai.ChatCompletion is no longer supported

By Updated

The error

Output
APIRemovedInV1:

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`

The same break also appears as:

Output
AttributeError: module 'openai' has no attribute 'ChatCompletion'

What it means

In November 2023, the openai Python library released v1.0 with a completely new interface. The old module-level calls — openai.ChatCompletion.create, openai.Completion.create, openai.Embedding.create — were removed, replaced by methods on a client object. Your code was written for the old library and is running on the new one. The API service is fine; only the Python wrapper changed.

Why it happens

Years of tutorials, courses and Stack Overflow answers use the pre-1.0 style, and a fresh pip install openai gives you the current library. Old code plus new library equals this error, every time.

How to fix it

1. Rewrite the call in the v1 style. The mapping is mechanical:

python
from openai import OpenAI

client = OpenAI()                      # reads OPENAI_API_KEY from the environment

resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Say hello in Hindi"}],
)
print(resp.choices[0].message.content)

The old/new correspondence:

Old (0.x)New (1.x+)
openai.api_key = "..."client = OpenAI(api_key="...")
openai.ChatCompletion.create(...)client.chat.completions.create(...)
openai.Embedding.create(...)client.embeddings.create(...)
resp["choices"][0]["message"]["content"]resp.choices[0].message.content

Responses are typed objects now — attribute access, not dictionary keys.

2. For a big old codebase, run the migration tool.

bash
openai migrate

It rewrites the old patterns in place. Review the diff afterwards; the tool handles the common shapes well.

3. Error classes moved too. openai.error.RateLimitError became openai.RateLimitError — update any except clauses, or they will silently stop catching.

4. Pinning openai==0.28 is the last resort. It freezes you out of newer models' features, current documentation and fixes. Use it only to keep an unmaintained legacy service alive, and record the debt.

How to prevent it

Check the publish date of any OpenAI code snippet against the v1.0 boundary (November 2023) — the presence of openai.ChatCompletion dates it instantly. Pin the major version in requirements (openai>=1,<3) so an upgrade is a decision rather than a surprise.