openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
Solution is probably just to defer client instantiation by one function call.
to become
def get_client():
return OpenAI()