How would I hide my files?

I need to include my API key to use the inference API, but how do I do that without making my key publicly visible in my space’s files?

I don’t want to make it private.

You can add secrets to have access to variables such as API keys in your Space :slight_smile:

If your app requires secret keys or tokens, don’t hard-code them inside your app! Instead, go to the Settings page of your Space repository and enter your secrets there. The secrets will be exposed to your app with Streamlit Secrets Management if you use Streamlit, and as environment variables in other cases.

1 Like

Out of curiosity, are these “secrets” accessible at all by moderators/Hugging Face in plain text? Or are they at least hashed and protected?

1 Like

I cannot even see the values of my own secrets :sweat_smile: these are hashed and protected as far as I know, but I’ll let @cbensimon give a final confirmation.

1 Like

so if I added a secret under “API_TOKEN” , I’d do something like:

import os

Yes, that looks good! Or os.environ["API_TOKEN"] should work as well. You can try it out with a dummy token first, print the value, and see it in the logs (click in “Running”)