I need to upload a Python script of a web application including an OpenAI API key to my GitHub Repository to deploy it in the Streamlit community cloud. But, when I deploy it, it works correctly only the first time. Since OpenAI recognizes it as a security breach. I get an email notification from OpenAI as below.
I get the following error when I Run the Web App in Streamlit, in the log.
raise self.handle_error_response(
openai.error.AuthenticationError: <empty message>
2023-05-16 10:35:17.560 Uncaught app exception
Traceback (most recent call last): ```
The brief answer is you should never do such a thing as your API key will be exposed to the public.
The correct way of doing this is specifying environmental variables
in your deployment environment, which you'll reference in your code. As every cloud Steamlit has an established approach for this, see their docs here. Hope this helps!