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:

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.