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.