Someone used my API key and used up all my limit!

Hi! I just got a mail from OpenAI that my monthly API limit was reached but I wasnt using my one and only API key this month. I checked the usage page and yes, someone used my API key the last 2 days and used GPT4, GPT4-Turbo & GPT4o.

I used the API key in a hugginface space project as a “Secret API-Token”, so it’s impossible someone sneaked in and stole it there. Not even I can uncover the “Secret Variables” once set. I checked the source code of my huggingface space to be sure but theres no API-Key in it. The space itself was deactivated since march and still is, so it wasnt the huggingface app itself. It’s using embeddings only anyway.

What happened? How did someone get my API-Key?

Impossible someone sneaked in: likely someone sneaked in. You can report the issue to HuggingFace, and document exactly which of their token mechanisms you assumed would keep one of your secrets safe.

But first review every bit of code you ever made, ever sync’d to a repository, everywhere you might have been using the API key and how you still know it. Someone easily may have control over your PC from you installing some fake backdoor app, AI utility you don’t understand, or other nefarious download.

As unfortunate as it is, @KptnTeddy, if that was the only place the API key was used, then it’s the likely source of the leak, plus your system and browser (if you use any 3rd party extensions).

I agree with @_j’s input on this as well, and would like to add that in your case, this could have been avoided by limiting the scope of the generated API key by using the restricted scope of the API key and limiting it to embeddings during API key creation.

Thank you both for your input!

  • I checked all my commits to huggingface (there where no commits to somewhere else): no API key in code. So no way to get the API key from my huggingface account, there where no logins since march anyway. If someone hacked the API key from huggingface, then its their own servers that are compromised.
  • I doubt someone sneaked into my PC, it’s a linux system dedicated to work, software only from official sources or from “trustworthy” companies like MS, Google, Oracle… no games, no apps. Browser Add ons are still a possibility. But how likely is it that someone recorded the api key months ago when I was setting the secret api key as a variable in my huggingface space and started using it now?
  • restricting the api key scope wasnt as granular back then as it is now… I restricted it to “model capabilities” which included the GPTs.

So we better delete all API keys that are not in use at the moment and rotate the keys frequently…


wouldn’t be the first time Hugging Face was hacked:


@KptnTeddy ditto for me. Notification threshold hit yesterday (I thought maybe I did use it that much), then hit my budget today and API requests denied. Same as you, my API key was only ever entered in the secure area of Huggingface, never in code, and the only project using it was private and paused for several months. I wonder if Huggingface has been compromised. Meanwhile I have deleted that API key.

1 Like

Ok, now it’s official, Huggingface Space Secrets where compromised. Received this email today from Huggingface:

Earlier this week our team detected unauthorized access to our Spaces platform, specifically related to Spaces secrets. As a consequence, we have suspicions that a subset of Spaces’ secrets could have been accessed without authorization.

Take care of your API keys!

1 Like