OpenAI error when client initialised

I’m trying to initialise OpenAI

from openai import OpenAI
OPENAI_API_KEY = anvil.secrets.get_secret(“OpnAiKey”)
client = OpenAI(OPENAI_API_KEY)

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

But I get this error

TypeError: OpenAI.__init__() takes 1 positional argument but 2 were given

The OpenAI docs show passing in the api key as a keyword argument, e.g. client = OpenAI(api_key=OPENAI_API_KEY)

1 Like

That worked. Many thanks