Hugging Face API Keys made Easy

Hugging Face provides tons of Machine Learning tools but to use many of them you need an API key. Let’s break down the process of getting and using those keys along with an explanation of the nuances of the different types of keys.

To get a key

  1. Log in to your Hugging Face account.
  2. Go to your tokens.
  3. Click on “Create new token”.
  4. Choose your token type. more on that below.
  5. Enter a unique name.
  6. Click “Create token”.
  7. Copy the token and save it somewhere safe. This is the only time you’ll be able to see it.

Note: You can and should create many tokens, one for each project. This way, if one token is compromised, you can delete it without affecting your other projects.


Token Types

Read - Read access only.

Write - Full read and write access to everything. Dangerous!

Fine-grained - Tuneable. This is the move!

Fine-grained access adheres to the most secure practices. You can choose which activities:

And within those activities, you determine exactly what the token allows:

Most of us are going to create the most dangerous token, the Write token and test with it. That’s fine, but be sure to delete it and create a fine-grained token once it is working.