Hugging Face API Key (Access Token): How to Get One and Keep It Safe

A Hugging Face API key is called an access token, and you create one at Settings, then Access Tokens: click "New token", pick a role and give it a name.

Use a fine-grained token for anything in production, since it reaches only the repos and permissions you choose.

Steps checked against Hugging Face's own docs in Nov 2026. Menus change, so if a screen looks different, follow the linked docs.

How to get a Hugging Face API key

  1. Sign in to Hugging Face and open Settings, then Access Tokens.
  2. Click "New token".
  3. Choose a role (fine-grained, read or write) and a name that says what the token is for.
  4. For a fine-grained token, tick only the repos and permissions the app needs.
  5. Copy the token and save it as an environment variable called HF_TOKEN, which the huggingface_hub library reads.

Read tokens can read every repo you can read, private and gated ones included. Write tokens can also push to every repo you can write to. Fine-grained tokens can be limited to one model or dataset, even inside an organization.

Tokens you haven't used for a year expire. Hugging Face emails you 30 days before, and expired tokens show as "Invalidated".

Check a key you already have

Not sure which service a key in your config belongs to, or whether you just pasted one somewhere? Paste it below to see what it is and how to revoke it.

Runs only in your browser. The check happens on this page. What you paste isn't sent anywhere, saved or logged, and the checker never contacts the provider. Want proof? Open your browser's network tab, or turn off Wi-Fi, and paste.

What a Hugging Face API key looks like

Hugging Face user tokens start with hf_ followed by 34 letters and digits. Organization API tokens start with api_org_. Both shapes are in the trufflehog and gitleaks rule sets.

How to store your Hugging Face API key safely

  • Pass it through HF_TOKEN or a file, never on the command line. Hugging Face points out that command-line arguments end up in shell history and logs.
  • Use one token per app or use case, so you can revoke one without breaking the rest.
  • Use fine-grained tokens in production, and read tokens only where an app truly needs to read everything.
  • In CI/CD, Hugging Face suggests Trusted Publishers (OIDC) instead of storing a token at all.

Never paste your Hugging Face API key into an AI chat

It usually happens while debugging. The error sits next to a config file, you paste the whole thing into ChatGPT or Claude, and the key goes in with everything else.

Once it's sent, the key is stored on someone else's servers, in the chat history, and possibly in training data, depending on your account settings. Deleting the chat doesn't take it back, so treat any key you pasted as exposed and rotate it.

We wrote a step-by-step guide for that moment: what to do in the first hour after pasting an API key into ChatGPT. And if a tool you installed might have read your keys, see how to check whether your AI keys were exposed.

What to do if your Hugging Face API key leaks

Rotate first and investigate second. A key that no longer works can't be misused.

  1. Open Settings, then Access Tokens.
  2. Click "Manage" next to the token. Delete it, or refresh it to get a new value.
  3. Update every app that used it, then check your repos for changes you didn't make if it was a write token.

Found someone else's leaked token? Hugging Face has a public endpoint to revoke it: POST https://huggingface.co/api/credentials/revoke with the token in a credentials array.

How Sequirly catches keys at the paste

We build Sequirly, a browser extension that checks what you're about to send to ChatGPT, Claude, Gemini and other AI tools. When a prompt contains an API key, a password or other sensitive data, Sequirly warns you before it leaves your browser, so you can remove it and send the rest.

Sequirly holds an API key before it reaches ChatGPT, then flags customer data in the next prompt.

The check runs inside your browser, and Sequirly says it never sees, stores or sends the values it finds.

There's plenty it doesn't do, so you know where the gaps are:

  • It doesn't scan your code, repos or servers. Use a secret scanner such as gitleaks for that.
  • It doesn't revoke keys or check whether a key is live. Rotation is still on you.
  • It only knows keys by their shape, so a key with no prefix (like Mistral's) can slip past it, just as it slips past the checker above.
  • It warns before it blocks, so a person can still choose to send.

Curious how to test that claim yourself? Our post on whether Sequirly is safe to install walks through a network test you can run.

Common Questions

What is a Hugging Face API key?

A Hugging Face API key is a user access token. It authenticates you to the Hugging Face Hub and its APIs, with the permissions of the role you picked.

Where do I find my Hugging Face token?

Your tokens are listed under Settings, then Access Tokens (huggingface.co/settings/tokens), where you can also create, refresh and delete them.

Should I use a read, write or fine-grained token?

Use a fine-grained token wherever you can, because it reaches only what you select. Hugging Face recommends fine-grained tokens for production.

Do Hugging Face tokens expire?

Yes, if unused. A token you haven't used for a year expires, and Hugging Face emails you 30 days before.

Sources

Guides for other API keys

Catch the key before it leaves

If you'd like a warning the next time a key ends up in a prompt, try Sequirly now. Or if you'd rather talk it through with us first, book a quick demo.