How to create Hugging Face API key (Access Token)

Let us see how to generate a Hugging Face Access Token. We discussed what is an access token in the previous lesson. If you do need an access token (e.g., for gated models or the Inference API), here are the steps to generate one.

Steps to generate a Hugging Face API Key (Access Token)

Step 1: Go to https://huggingface.co/join and sign up as we did below to create a new account:

Create a new account and SignUp on Hugging Face

Above, click Next

Step 2: Create your account. Add your username and full name. You can leave the optional boxes and click Create Account as shown below:

Create your profile on Hugging Face

Step 3: Click on your profile picture in the top-right corner and navigate Access Tokens:

Read the Access Tokens section on Hugging Face

Step 4: Now, it is not allowing me to create an access token. The Create new token is disabled.

To fix this, go to your email account and verify your account. The notification is also visible as shown below “Please confirm your account email address before creating access tokens”:

Confirm your email account on Hugging Face

Step 5: We will click on the link in the email to verify:

Click the link sent by Hugging Face on your email account to verify

Step 6: Now, click Create new token to generate a token.

Create a new token on Hugging Face

Step 7: Add a name to the token:

Give a name to the new token on Hugging Face

Step 8: We have added a name to the token:

We added the token name on Hugging Face

Step 9: Now, go below and click Create token:

Click Create Token to create your new token

Step 10: The key was created successfully. Copy it and keep it secure. Do not share the key with anyone. Click Done:

A new access token created on Hugging face

Step 11: Now, our keys are visible. Here, all your keys will be visible. The usage date will also be visible here:

The new access token visible on Hugging Face under your profile

Example: Using a Hugging Face Access Token

Now, you can set the access token (key) in the code below:

Example: No Access Token Needed

Here, we are using a public model therefore access token isn’t required:

Summary

  • No Token Needed: For public models used locally via transformers.
  • Token Needed: For gated models, private models, or when using the Hugging Face Inference API (HuggingFaceHub in LangChain).

Security Tips:

  • Keep your token private and avoid sharing it publicly.
  • Use environment variables or secure storage to manage tokens.
  • Regenerate tokens if compromised.

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

What is the Hugging Face Access Token
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading