How to manage user secrets and API Keys?

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)
6 Likes