Client error using openai 1.6.1 say i given two argument but only have one

Hello all maybe you give me a few ideas how to fix… I decide I try out openai and playing around but have bug right off the bat and tried to fix with no luck.
Using PyCharm Community 2023.2.5
verified openai version 1.6.1 in lib

I got other coding before the client stuff to work in earlier projects did
listen-speech to text, output print & speech

6 import openai
8 api_key = 'sk-1rodpuXlpg6E9si7'  # remove char from my code before post
9 client = openai.Client(api_key)

error repeated this my ways of coding it, even tried chatGPT to help and it runs me thru loop as see all correct

Note it looks like coming from main.py as only common error code both debug and run

Traceback (most recent call last):

DEBUG - LISTED LINES OF ERRORS
LINE 1
File “C:\Program Files\JetBrains\PyCharm Community Edition 2023.2.5\plugins\python-ce\helpers\pydev\pydevd.py”, line 1500, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
LINE 2
File “C:\Program Files\JetBrains\PyCharm Community Edition 2023.2.5\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py”, line 18, in execfile
exec(compile(contents+“\n”, file, ‘exec’), glob, loc)
DEBUG- LISTED

RUN ONLY LIST THIS ERROR SAME CODE AS ABOVE
LINE 3
File “C:\Users\vrpro.LATTEPANDASIGMA\PycharmProjects\pythonProject11\main.py”, line 9, in
client = openai.Client(api_key)
TypeError: init() takes 1 positional argument but 2 were given

Process finished with exit code 1

Thank you in advance all for comments

The default method of the openai python library is to use an OPENAI_API_KEY environment variable set in your operating system. Then the API calls just work everywhere.

The client creation accepts parameters which are non-positional, meaning you need to specify the name of the parameter you are setting, such as:

from openai import OpenAI
o_client = OpenAI(timeout = 60)

That is the same way you would specify the parameter api_key and its value.

1 Like

Wow I will try this as weird all the sample I reviewed not show this as even tried VS 2022 and Exception Thrown same error. Just surprised all the sample code shows away that not works.

Yes I will add your way to Environment Var as understand the OPENAI_API_KEY alway there anytime called…