Safeguard Docs
Integrations

Hugging Face

Connect Hugging Face Hub models to Safeguard. The access the user access token needs, which token types work, and step-by-step setup.

What it does

The Hugging Face card connects Safeguard to models on the Hugging Face Hub. Safeguard lists your models (or the ones you add by URL) and scans each selected model's files for security issues, such as unsafe serialization formats and embedded code, and records it in your AI inventory. Find the card under Integrations on the Project/Product tab.

Public vs private

PublicPrivate
What you enterA model URL, such as https://huggingface.co/<owner>/<model>A Name and a Hugging Face user access token
Credential neededNoneA user access token with read access
What you can selectThe public models you add by URLYour models and the models of organizations you belong to, plus any you add by URL, including private and gated models the token can read

Supported auth methods

MethodUse it whenNotes
User access token, fine-grainedRecommendedLimit it to the models or organizations Safeguard should read
User access token, readSimple setupReads every repository you can read
NonePublic modelsNothing to create

Permissions required

Safeguard only reads. It never pushes commits, edits model cards, opens discussions or changes settings.

Fine-grained token

Permission (Hugging Face token settings)Required?What Safeguard uses it for
Read access to the repositories to scan (your namespace, a selected organization, or selected repositories)RequiredChecking the token (/api/whoami-v2), listing models (/api/models), reading refs and revisions, and downloading model files for the scan
Read access to public gated repos you can accessOptionalScanning gated models you have been granted access to
Any write, discussion, inference, webhook or billing permissionNot usedLeave them off

Read token

Token roleRequired?What Safeguard uses it for
readRequiredThe same calls as above, across every repository you and your organizations own

Least privilege: a fine-grained token with read access to only the models or organization you want scanned.

Token types

Token typeWorks?Notes
Fine-grained user access token, read onlyYes (recommended)Hugging Face recommends fine-grained tokens for production use
read user access tokenYes
write user access tokenWorks, not recommendedSafeguard never writes
Token scoped to an organization that requires approvalOnly after approvalIt stays Pending until an organization administrator approves it
Read or write token in an organization that only allows fine-grained tokensNoThe organization rejects it with a 403

Expiry: Hugging Face user access tokens do not expire on their own. Rotate the token (Hugging Face calls it refresh) at least every 90 days.

What we never need: write access, inference or billing permissions, organization admin rights, or access to datasets and Spaces.

Step-by-step setup

Create the credential in Hugging Face

  1. Sign in to Hugging Face and open Settings > Access Tokens (https://huggingface.co/settings/tokens).
  2. Click New token.
  3. Choose Fine-grained, give it a name (for example Safeguard), and grant read access to the repositories, or the organization, to scan. Add read access to gated repositories only if you need them.
  4. Create the token and copy it (it starts with hf_).

Or with the Hugging Face CLI

Hugging Face has no CLI command that creates a token. To check the token before you paste it into Safeguard:

hf auth login --token "$HF_TOKEN"
hf auth whoami

Connect it in Safeguard

  1. Open Integrations and choose the Project/Product tab.
  2. Click Connect on the Hugging Face card.
  3. For public models, choose Public, enter a Name, paste a model URL, click Add, then Next.
  4. For private models, choose Private, enter a Name and paste the token into Access Token, then verify it.
  5. Click Next, select the models and revisions to scan, review, and connect.

Webhooks and triggers

This integration has no webhooks. Each selected model is scanned when you connect it; to rescan new revisions, set a schedule under Integrations > Scheduled or rescan by hand from the project.

What we read and store

  • Read: your account name, model names, refs and revisions, and the files of the models you select for scanning.
  • Stored: the connection's settings, the scan results and AI inventory entry of each scanned model, and the token, which is encrypted at rest and never shown again after you save it.
  • Not stored: model weights. Files are read for the scan and not kept.
  • No customer data from this integration is sent to third-party LLMs.

Troubleshooting

Message you seeCauseFix
HuggingFace API token requiredThe token field is emptyPaste the hf_... token
Invalid API tokenHugging Face rejected the token (deleted, refreshed, or mistyped)Create or refresh the token and paste it again
Model is private. Authentication required.A private model was added on the Public tabUse the Private tab with a token
A gated or organization model fails with 403The token lacks read access to that repository, is pending approval, or the organization requires fine-grained tokensGrant read access in the token's settings, wait for approval, or use a fine-grained token

Rotation and disconnect

  • Rotate: refresh the token under Settings > Access Tokens > Manage, find the connection under Project Configurations on the Project/Product tab, choose Update, paste the new token and save.
  • Disconnect: choose Delete from the connection's menu under Project Configurations and confirm Delete configuration, then delete the token in Hugging Face.

Vendor references

On this page