Subject: Trouble using Hugging Face API token in a private Space Message: Hi Hugging Face Team, I'm building a Space where I want to call an external Hugging Face model using the API. I've followed the steps to make my Space private and tried to includ

Subject: Trouble using Hugging Face API token in a private Space

Message:

Hi Hugging Face Team,

I’m building a Space where I want to call an external Hugging Face model using the API. I’ve followed the steps to make my Space private and tried to include my token, but I keep getting this error:

Error: It appears that one or more of your files contain valid Hugging Face secrets, such as tokens or API keys. It is important to keep your secrets private and not expose them in code that is publicly accessible.

However, my Space is already set to private, and I’m still receiving this error. I even tried moving the token to a separate file, but no luck.

Can you please guide me on the correct way to use my hf_… token inside a Space (private or public) to call a Hugging Face API securely?

Thanks in advance for your help!

Best regards,
Ahmad

1 Like

It seems that the security scanner also works in Private mode. When handling tokens in Spaces, it is recommended to either pass the token each time or use Secrets.