# Error AttributeError: module 'openai' has no attribute 'ChatCompletion'

**URL:** <https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100>\
**Category:** API\
**Tags:** gpt-4\
**Created:** [November 8, 2023, 8:48pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100 "2023-11-08T20:48:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 8:48pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/1 "2023-11-08T20:48:44Z")

</div>

Hello  
I am trying to use the gpt-4 model in my epro code when trying to run the service it gives me the following error

AttributeError: Module ‘openai’ does not have attribute ‘ChatCompletion’

For what is this? Is it possible to use that model?

---

<div class="post-metadata">

**Author:** ![PaulBellow](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/paulbellow/32/597962_2.png) [@PaulBellow](https://community.openai.com/u/PaulBellow)\
**Post date:** [November 8, 2023, 8:49pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/2 "2023-11-08T20:49:53Z")

</div>

I’d make sure you have the latest OpenAI library and that it’s compatible with your code.

---

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 8:55pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/3 "2023-11-08T20:55:31Z")

</div>

![image](https://us1.discourse-cdn.com/openai1/original/3X/6/8/68ca66def090ad4e21e9743c319490f4a2a2218b.png)

How can you advise me to have this library?

Attached is a screenshot of where I update the library.

---

<div class="post-metadata">

**Author:** ![PaulBellow](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/paulbellow/32/597962_2.png) [@PaulBellow](https://community.openai.com/u/PaulBellow)\
**Post date:** [November 8, 2023, 8:58pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/4 "2023-11-08T20:58:16Z")

</div>

If your code was using that old of a library, it’s likely not compatible with modern library.

You’d have to post code snippets for us to be able to help. Is it running after updating library? Still same error?

---

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 9:01pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/5 "2023-11-08T21:01:08Z")

</div>

This is my code

 ![image](https://us1.discourse-cdn.com/openai1/original/3X/d/d/dd086cf7d1532baf17057206227c6352a497067f.png)

---

<div class="post-metadata">

**Author:** ![PaulBellow](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/paulbellow/32/597962_2.png) [@PaulBellow](https://community.openai.com/u/PaulBellow)\
**Post date:** [November 8, 2023, 9:14pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/6 "2023-11-08T21:14:08Z")

</div>

Is it running after updating library? Still same error?

Since you did such a major update on the library, you might try uninstalling it an installing fresh. Most likely a library error, though…

---

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 9:24pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/7 "2023-11-08T21:24:51Z")

</div>

I uninstalled the library and reinstalled it and it still gives me the same error.

What else can I validate or what changes can be made to the code?

---

<div class="post-metadata">

**Author:** ![NotFenixio](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/notfenixio/32/205000_2.png) [@NotFenixio](https://community.openai.com/u/NotFenixio)\
**Post date:** [November 8, 2023, 9:26pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/8 "2023-11-08T21:26:01Z")

</div>

How’s your file called? Do you have any files in your current directory called “openai”?

---

<div class="post-metadata">

**Author:** ![PaulBellow](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/paulbellow/32/597962_2.png) [@PaulBellow](https://community.openai.com/u/PaulBellow)\
**Post date:** [November 8, 2023, 9:27pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/9 "2023-11-08T21:27:00Z")

</div>

Good idea. It sounds like it’s not reading the library correctly?

---

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 9:33pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/10 "2023-11-08T21:33:32Z")

</div>

The folder where I have the files is called openai-quickstart-python, and inside this folder I have several files that end in .py and the static, templates and venv folders.

---

<div class="post-metadata">

**Author:** ![NotFenixio](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/notfenixio/32/205000_2.png) [@NotFenixio](https://community.openai.com/u/NotFenixio)\
**Post date:** [November 8, 2023, 9:37pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/11 "2023-11-08T21:37:13Z")

</div>

And how’s the file you’re trying to execute the code in called?

---

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 9:40pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/12 "2023-11-08T21:40:05Z")

</div>

The file where I have the code is called app.py

---

<div class="post-metadata">

**Author:** ![PaulBellow](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/paulbellow/32/597962_2.png) [@PaulBellow](https://community.openai.com/u/PaulBellow)\
**Post date:** [November 8, 2023, 9:43pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/13 "2023-11-08T21:43:51Z")

</div>

Is GPT-4 working for you in Playground?

Can you try to connect via cURL to make sure it works that way?

---

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 9:54pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/15 "2023-11-08T21:54:23Z")

</div>

Yes, I tried it in playgroud and it works:

And it also works with postman

---

<div class="post-metadata">

**Author:** ![PaulBellow](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/paulbellow/32/597962_2.png) [@PaulBellow](https://community.openai.com/u/PaulBellow)\
**Post date:** [November 8, 2023, 10:01pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/16 "2023-11-08T22:01:28Z")

</div>

Yeah, I’m out of ideas. With that error, though, it sounds like it’s not loading the correct library.

Maybe set-up a test script with just basics to see if it works?

---

<div class="post-metadata">

**Author:** ![juanjose.espinoza](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/juanjose.espinoza/32/511656_2.png) [@juanjose.espinoza](https://community.openai.com/u/juanjose.espinoza)\
**Post date:** [November 8, 2023, 10:20pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/17 "2023-11-08T22:20:12Z")

</div>

If it’s strange, I tried on another server, updated the library and it gives me the same error, could it be the python version?

---

<div class="post-metadata">

**Author:** ![kait](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/kait/32/148482_2.png) [@kait](https://community.openai.com/u/kait)\
**Post date:** [November 8, 2023, 10:26pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/18 "2023-11-08T22:26:36Z")

</div>

I think you have to use chat.completion in the update now, so it would look something like this:

```auto
  completion = openai.chat.completions.create(
    model=self.model,
    messages=self.get_messages(prompt, question),
    max_tokens=500,
    temperature=float(self.temperature),
    
  )
response = completion.choices[0].message.content

```

---

<div class="post-metadata">

**Author:** ![Shebi](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@Shebi](https://community.openai.com/u/Shebi)\
**Post date:** [November 8, 2023, 10:33pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/19 "2023-11-08T22:33:14Z")

</div>

Yeah, also encountering the same issue.

```auto
    params = {
        "model": "gpt-4-vision-preview",
        "messages": PROMPT_MESSAGES,
        "api_key": os.environ["OPENAI_API_KEY"],
        "headers": {"Openai-Version": "2023-11-07"},
        "max_tokens": 500,
    }

    result = openai.ChatCompletion.create(**params)
    print(result.choices[0].message.content)
    return result.choices[0].message.content

```

Im doing everything exactly as from latest Jason AI video and on his video you can see openai.ChatCompletion.create works fine.

Is it possible it doesn’t work because of this major outage across ChatGPT and API?

---

<div class="post-metadata">

**Author:** ![wclayf](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/wclayf/32/184514_2.png) [@wclayf](https://community.openai.com/u/wclayf)\
**Post date:** [November 8, 2023, 10:36pm UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/20 "2023-11-08T22:36:35Z")

</div>

You should put a debug statement in the code and inspect the ‘openai’ variable to see what it contains (I think you should be able to see what methods are even on it). It’s probably an outdated version of the library, like others have said. If it was null seems like you’d get a different error.

---

<div class="post-metadata">

**Author:** ![jaburg](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jaburg/32/241119_2.png) [@jaburg](https://community.openai.com/u/jaburg)\
**Post date:** [November 9, 2023, 9:59am UTC](https://community.openai.com/t/error-attributeerror-module-openai-has-no-attribute-chatcompletion/485100/21 "2023-11-09T09:59:05Z")

</div>

@Shebi You are correct. It feels like they changed it overnight. This works in a Jupyter notebook

```auto
    import openai
    response = openai.chat.completions.create(
        model="gpt-4",
        messages=[
            {"role": "system", "content": "You are a 5 year old"},
            {"role": "user", "content": "what is pi"},
        ] 
    )
    
    message_content = response.choices[0].message.content
    print (message_content)

```
