How to manage user secrets and API Keys?

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?

hi @KushwanthK , You can access secrets and variables on your Space Settings page

https://huggingface.co/spaces/USER/SPACE_ID/settings

I replied to this question here: https://huggingface.co/spaces/ysharma/ChatGPT4/discussions/23#65f70560dd3cc437a85d2aea

Would be nice if the huggingface’s team adds this little detail to the docs: Spaces Overview

1 Like

To use your environment variables in a secure way you need to do this:

  1. Go to https://huggingface.co/spaces/USER/SPACE_ID/settings

  2. Create Private Secret. Let’s say you name it “YOUR SECRET KEY”

  3. 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)
3 Likes