Ensuring API_KEY Security in Google Colab Notebooks

1 min read

In the Cohere Google Colab notebook, you will notice that the API key is hardcoded.
# Setup the Cohere client
api_key = 'api_key' # Paste your API key here. Remember to not share it publicly
co = cohere.Client(api_key)
When I saved this on GitHub, I knew I was hardcoding the key. Saving the API key in plain sight within the Cohere Google Colab notebook poses a security risk, especially when saving the code on GitHub.
from getpass import getpass
token = getpass('Enter token here')
co = cohere.Client(token)
getpass module provides an ability to prompt the user for a value, usually a password, without echoing what they type to the console.
The above code helps you to type in the API key on runtime. The user-entered input is saved in var.
I hope you find this insightful.
0
Subscribe to my newsletter
Read articles from Priti Solanki directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
