Skip to content
Nilay Kabariya

Entry No.089·AI··3 min read

module 'openai' has no attribute 'ChatCompletion', tested

AttributeError: module 'openai' has no attribute 'ChatCompletion', or 'no longer supported in openai>=1.0.0'. Five SDK versions tested.

The error, verbatim

Jump to the fix ↓
AttributeError: module 'openai' has no attribute 'ChatCompletion'
✓ Reproduced on Windows 11 Pro

Tested on

openai (Python)
0.26.5, 0.28.1, 1.40.0, 1.55.3, 3.37.0
Python
3.14.5
OS
Windows 11 Pro
Contents
  1. Rewrite the call for openai 1.0 and later01
  2. Two more errors right after the rewrite02
  3. openai.api_base is ignored without an error03
  4. Or keep the old code on 0.2804
  5. How this was tested05

openai.ChatCompletion belongs to the old SDK, before 1.0. Code written for it fails on any version since, but not always with the same error. I ran the same old call on five versions:

openai.ChatCompletion.create(...) on What happened
0.26.5 AttributeError: module 'openai' has no attribute 'ChatCompletion'
0.28.1 worked
1.40.0, 1.55.3, 3.37.0 APIRemovedInV1: You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0

So the AttributeError is the rarer one. It came from two places in my tests:

  • A version older than 0.27. ChatCompletion didn’t exist yet.
  • A file of your own named openai.py. With one next to my script, import openai loaded that file instead of the package, and every version gave the same AttributeError. Python 3.14 printed no hint about the name clash.

If you have an openai.py, rename it. Otherwise, check your version with pip show openai.

Rewrite the call for openai 1.0 and later

From 1.0 on, the calls hang off a client object.

from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY
response = client.chat.completions.create(
    model="gpt-4.1-mini",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

The old names map like this. openai.Image, openai.Moderation and openai.Model raised the same APIRemovedInV1 as the rest:

Before 1.0 1.0 and later
openai.ChatCompletion.create(...) client.chat.completions.create(...)
openai.Completion.create(...) client.completions.create(...)
openai.Embedding.create(...) client.embeddings.create(...)
openai.Image.create(...) client.images.generate(...)
openai.Moderation.create(...) client.moderations.create(...)
openai.Model.list() client.models.list()
openai.error.RateLimitError openai.RateLimitError
openai.api_base = ... OpenAI(base_url=...)

Two more errors right after the rewrite

The reply is no longer a dict. Old code read response["choices"][0]["message"]["content"]. On the new SDK, that line raised:

TypeError: 'ChatCompletion' object is not subscriptable

Use attributes: response.choices[0].message.content. If other code expects a dict, response.model_dump() returns one.

openai.error is gone. except openai.error.RateLimitError: raised AttributeError: module 'openai' has no attribute 'error' on 1.55.3 and 3.37.0. The exception classes now sit on the module itself.

except openai.RateLimitError:

openai.api_base is ignored without an error

This one doesn’t raise anything. On 1.55.3 and 3.37.0, I set openai.api_base to a local server and called openai.chat.completions.create(). The request skipped my server and went to api.openai.com, where my test key got a 401. If you used api_base to reach Azure, a proxy or a local model, the new SDK quietly calls OpenAI instead.

The setting is called base_url now, and it ends with a slash:

openai.base_url = "http://localhost:8000/v1/"
# or, on a client:
client = OpenAI(base_url="http://localhost:8000/v1/")

Or keep the old code on 0.28

The error message itself suggests pip install openai==0.28. That still worked: on Python 3.14.5, 0.28.1 installed, and the old openai.ChatCompletion.create() call reached the real API. The API answered with my key’s credit error, so the request itself was accepted. It’s a stopgap, though: 0.28 gets no fixes, and no new API features such as the Responses API.

How this was tested

Windows 11 Pro, Python 3.14.5, October 23, 2026. Each openai version ran in its own venv against a local HTTP server that recorded every request and answered with a fixed reply. Only the 0.28.1 check went to the real API, with a key that has no credits. The shadowing case put a one-line openai.py next to the script. I didn’t run the openai migrate command that the error message mentions. The test scripts are public.

— N.K., end of entry No.089

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.088

    Responses.create() unexpected keyword argument: new names

    max_tokens, messages, response_format, seed: their names in OpenAI's Responses API, tested. Plus the 'proxies' TypeError from httpx 0.28.

    > TypeError: Responses.create() got an unexpected keyword argument 'max_tokens'

    AI6 min
  2. No.020

    Fix: The OPENAI_API_KEY environment variable is missing or empty

    OpenAI's SDK or Codex CLI says your key is missing, though it's in .env. Every wording and its fix, plus the 401 you get when an old key wins.

    > OpenAIError: The OPENAI_API_KEY environment variable is missing or empty; either provide it,

    AI7 min
  3. No.087

    Claude SDK: unexpected keyword argument temperature, betas

    Messages.create() got an unexpected keyword argument after an anthropic upgrade, plus what SDK 2.0 (October 21) breaks next. Python and TypeScript, tested.

    > TypeError: Messages.create() got an unexpected keyword argument 'temperature'

    AI4 min

Post card · Every Sunday

What broke this week.

One email on Sundays: the Node, TypeScript, Python and AI SDK releases that broke builds that week, each one reproduced, with a link to the fix that worked. Never shared, and you can leave any time.

— Nilay

or follow by RSSor on X

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text