# 'OpenAI' object has no attribute 'Completion'

**URL:** <https://community.openai.com/t/openai-object-has-no-attribute-completion/1089155>\
**Category:** API\
**Created:** [January 13, 2025, 3:52am UTC](https://community.openai.com/t/openai-object-has-no-attribute-completion/1089155 "2025-01-13T03:52:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jochenschultz](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jochenschultz/32/772274_2.png) [@jochenschultz](https://community.openai.com/u/jochenschultz)\
**Post date:** [January 13, 2025, 5:59am UTC](https://community.openai.com/t/openai-object-has-no-attribute-completion/1089155/2 "2025-01-13T05:59:04Z")

</div>

Here is a basic example:

```python
from openai import OpenAI

client = OpenAI()

PROMPT = "give me a random poem"

def call_openai_api():

    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": PROMPT}],
        temperature=1,
        max_tokens=300,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0
    )

    print(response.choices[0].message.content.strip())

if __name__ == " __main__":
    call_openai_api()

```

save it as openai\_test.py

Then you typically create a virtual env (optional but suggested)

```bash
python3 -m venv venv
source venv/bin/activate

```

And you will need to export the OPENAI\_API\_KEY - e.g. on ubuntu you do:

```bash
export OPENAI_API_KEY=sk....your_key_here

```

There is no need to explicitly set that for the OpenAI object - it just reads that OPENAI\_API\_KEY env variable per default.

and then you can install the requirement / openai lib and run the script

```bash
pip install openai
python3 openai_test.py

```

you can deactive the venv by just typing

```bash
deactivate

```

---

_[View the full topic](https://community.openai.com/t/openai-object-has-no-attribute-completion/1089155)._
