Answers for LLM inference engineers

ImportError: cannot import name 'OpenAI' from 'openai', module 'openai' has no attribute 'error', openai.ChatCompletion: which openai version has it

from openai import OpenAI needs openai 1.0.0 (2023-11-06) or later; on 0.x it raises this ImportError. Check which copy is imported: python -c "import openai; print(openai.__version__, openai.__file__)". A 0.x version means upgrade (pip install -U openai) in that environment; a path into your project means a file named openai.py is shadowing the library. The other direction: 0.x code on 1.x. openai.error is gone since 1.0.0 (the exceptions are openai.RateLimitError and so on). openai.ChatCompletion imports again from 1.2.0 but is a placeholder that raises APIRemovedInV1 when used. To keep 0.x code, pin pip install "openai<1.0.0" (0.28.1). For any other name, including openai.types, paste the error below.

Published 2026-11-18 · Data as of 2026-12-03 · openai 0.2.6 to 3.63.0, the first release of each of 251 minor versions, with patch releases that differ noted · read from the source of each release tag, nothing was installed or run (how, limits) · Corrected 2026-12-05

Corrected on 2026-12-05: this page read only the first release of each minor version, so a name added or removed in a patch release was dated to the next minor. For example, openai.FineTuningJob is in 0.27.9 (2023-08-22), not only from 0.28.0, and from openai import Omit works from 1.56.2 (2024-12-04), not only from 1.57.0. Every release was then read once from PyPI: 50 top-level names (and 2,168 module-and-name pairs in all) differ, in a release this page did not read, from what the page said for that release (0.11.0, which has no git tag, had been given the names of 0.10.0). The lookup and the placeholder table now give those patch releases. The per-minor ranges are unchanged.

Examples:

Runs in your browser on openai.json (1340 KB); nothing you paste is sent anywhere. Covers 35,148 module-and-name pairs in 2291 modules.

Which 0.x names still import on 1.x, but only as placeholders?

These 15 names were classes in 0.x. From 1.2.0 (2023-11-09) the import succeeds again, but the object raises on first use: APIRemovedInV1: "You tried to access openai.X, but this is no longer supported in openai>=1.0.0". The same message suggests openai migrate or pip install openai==0.28. In 1.0.0 and 1.1.x the import itself fails.

NameA real class in
openai.Audio0.27.0 to 0.28.1
openai.ChatCompletion0.27.0 to 0.28.1
openai.Completion0.2.6 to 0.28.1
openai.Customer0.18.0 to 0.28.1
openai.Deployment0.18.1 to 0.28.1
openai.Edit0.16.0 to 0.28.1
openai.Embedding0.11.6 to 0.28.1
openai.Engine0.2.6 to 0.28.1
openai.ErrorObject0.2.6 to 0.28.1
openai.File0.2.6 to 0.28.1
openai.FineTune0.4.0 to 0.28.1
openai.FineTuningJob0.27.9 to 0.28.1
openai.Image0.25.0 to 0.28.1
openai.Model0.10.0 to 0.28.1
openai.Moderation0.20.0 to 0.28.1

Where did the openai.error exceptions go?

To the top level of openai, for the 6 that kept their names; the others have no class of the same name in 1.x. except openai.error.RateLimitError: becomes except openai.RateLimitError:.

0.xNow
openai.error.APIConnectionErroropenai.APIConnectionError (from 1.0.0)
openai.error.APIErroropenai.APIError (from 1.0.0)
openai.error.AuthenticationErroropenai.AuthenticationError (from 1.0.0)
openai.error.CardErrorno class of that name in 3.63.0
openai.error.IdempotencyErrorno class of that name in 3.63.0
openai.error.InvalidAPITypeno class of that name in 3.63.0
openai.error.InvalidRequestErrorno class of that name in 3.63.0
openai.error.OpenAIErroropenai.OpenAIError (from 1.0.0)
openai.error.OpenAIErrorWithParamCodeno class of that name in 3.63.0
openai.error.PermissionErrorno class of that name in 3.63.0
openai.error.RateLimitErroropenai.RateLimitError (from 1.0.0)
openai.error.ServiceUnavailableErrorno class of that name in 3.63.0
openai.error.SignatureVerificationErrorno class of that name in 3.63.0
openai.error.Timeoutopenai.Timeout (from 1.0.0)
openai.error.TryAgainno class of that name in 3.63.0

Names under openai.types that moved

The 1.x and later releases move types between modules too. For example, openai.types.beta.VectorStore worked from 1.21.0 to 1.65.5 and is openai.types.VectorStore from 1.66.0. When a name left a module, the lookup lists the other modules that had it in that release.

How was this read, and how was it checked?

From the source of each release tag, with Python's ast module; no release was installed or imported. 0.x is read from openai/, 1.x and later from src/openai/. A module's names are everything it binds at module level, including what star imports bring in. The placeholders are read from the SYMBOLS list in src/openai/lib/_old_api.py, which openai/__init__.py star-imports. Dates come from PyPI.

Checks, by a second reading: (1) each of the 271 top-level names is found as plain text in __init__.py (or the modules it star-imports) in every release of its range (36,539 name-and-release pairs), and is not bound there in the release on either side (206 edges). (2) A regular expression finds 70,180 definitions in 10,378 file versions; all are among the names read. (3) 8 known facts hold, among them the versions in the public reports under Sources.

Limits

Questions

How do I fix "ImportError: cannot import name 'OpenAI' from 'openai'"?

The OpenAI client class exists from openai 1.0.0 (2023-11-06). Check the version the error comes from with python -c "import openai; print(openai.__version__, openai.__file__)": if it is 0.x, run pip install -U openai in that environment. If the path points into your own project, a file named openai.py (or a folder named openai) is shadowing the library; rename it.

How do I fix "AttributeError: module 'openai' has no attribute 'error'"?

openai 1.0.0 removed the openai.error module. The exception classes are at the top level now: openai.RateLimitError, openai.APIError, openai.AuthenticationError, openai.APIConnectionError and openai.OpenAIError keep their names; openai.InvalidRequestError has no class of that name in 1.x.

My old code calls openai.ChatCompletion.create. What happens on openai 1.x?

From 1.2.0 (2023-11-09), "from openai import ChatCompletion" and openai.ChatCompletion succeed, but they are placeholders: using them raises APIRemovedInV1, "You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0". In 1.0.0 and 1.1.x the name is missing altogether. Rewrite to client = OpenAI(); client.chat.completions.create(...), or pin pip install openai==0.28.

Which version should I pin to keep openai 0.x code running?

openai 0.28.1 is the last 0.x release; pip install "openai<1.0.0" installs it. The 1.x message itself suggests openai==0.28.

Sources

The same data as JSON: openai.json, licensed CC BY 4.0.

Related: "cannot import name ... from 'langchain'" · "... from 'transformers'" · "... from 'huggingface_hub'".