How to encrypt/restrict access to `openai.api_key` within jupyter notebook like online code-editor

We need to let users to try out openai api-calls within jupyter notebook like online code editor environment,

  • users should be able to run most of the openai python API calls (hands-on tutorials for internal training)
  • but we need to restrict users from printing openai.api_key or if user tries to print it should print only encrypted value, within the online code editor
    Any help / reference is much appreciated. openai #api_key

Hi JoshuaB! Thanks for bringing this question up!
What I usually do, when running notebooks and needing an API Key, is have a cell with this code:

from getpass import getpass

# type your API KEY, once asked
API_KEY = getpass('Enter API key: ')

So, you might be asked to copy/type your API key without anyone “seeing it” and now have the key in this variable API_KEY

Hope this answers your question and helps! :smiley:

1 Like

Thanks @lesly.zerna for the reply.
our requirement is not just hiding openai.api_key while typing, during the session. since we need to provide access to the notebook itself (similar to the short courses), but, need to mask/encrypt when the user tries to print / access openai.api_key(limiting api_key usage only to that particular notebook)
Any pointers to how api_key access is being controlled, in notebooks shared with short courses will be a great help.

1 Like

Hey Guys,
Yes I too think that this looks like a security concern of itself. I can really just access the OpenAI API Key that Deepliearning has by executing
openai.api_key

That looks like free API Calls to me. (duh I know you must have it set rate limits, but still…)
@lesly.zerna I’m sure engineers at deeplearning.ai are aware of this. How is the dev team explaining that this is not a security break?

1 Like

Thanks for reporting! I’m checking that with the team! Which course in specific are you checking? Thank you!

1 Like

It is indeed dummy data. (that openai.api_key’s ouput). See, I’ve tested trying to “use that API Key” and indeed got this error:
AuthenticationError: Your authentication token is not from a valid issuer.