How to manage user secrets and API Keys?
huggingface.coSpaces OverviewWe’re on a journey to advance and democratize artificial intelligence through open source and open science.As per the above page I didn’t see the Space repository to add a new variable or secret.new variable or secret are deprecated in settings page. How to handle the API Keys and user secrets like Secrets Manager?Screenshot 2024-01-04 at 1.48.17 AM1862×838 109 KB
2024-01-04T23:26:50Z
hi@KushwanthK, You can access secrets and variables on your Space Settings pagehttps://huggingface.co/spaces/USER/SPACE_ID/settings
2024-03-17T15:05:44Z
I replied to this question here:https://huggingface.co/spaces/ysharma/ChatGPT4/discussions/23#65f70560dd3cc437a85d2aeaWould be nice if the huggingface’s team adds this little detail to the docs:Spaces Overview
2024-03-17T15:07:08Z
To use your environment variables in a secure way you need to do this:Go tohttps://huggingface.co/spaces/USER/SPACE_ID/settingsCreate Private Secret. Let’s say you name it “YOUR SECRET KEY”Go to your app.py script and add these lines:import os

api_key = os.getenv("YOUR SECRET KEY")
client = OpenAI(api_key=api_key)