Module 'openai' has no attribute 'Client'

While trying to create OpenAI client, I get following error

module 'openai' has no attribute 'Client'

This is my code

import openai
client = openai.Client(api_key=os.environ['OPENAI_API_KEY'],)

Output of “pip show openai”

Name: openai
Version: 0.28.0
Summary: Python client library for the OpenAI API
Author: OpenAI
Location: /usr/local/lib/python3.10/site-packages
Requires: aiohttp, requests, tqdm

I have tried different version of OpenAI suggested in this thread “community.openai[dot]com/t/attributeerror-module-openai-has-no-attribute-chatcompletion/81490” but none worked.

Hello and welcome to the forum!
The latest version of the openai library is currently at 1.X

Try updating and see if that solves your issue.

1 Like

I installed to latest version of OpenAI which is “1.2.4” but that didn’t work

Try writing “client” instead of “Client” :wink:
(There’s a difference in capitalization)


Same error persist but this time with “client”.

I was able to get mine working by doing this:

import openai
import requests
from openai import OpenAI
client = OpenAI()

Hopefully that might work for you too.

From what I understand this automatically uses your saved API key

1 Like

This really did work for me. Thank you!


Don’t thank me, GPT-4 told me how to fix it :rofl:

1 Like