> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opal.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Hugging Face

> Learn how to connect Opal to Hugging Face to manage organization roles and resource group membership.

With the Hugging Face integration, you can manage access to your Hugging Face organization from Opal:

* Allow users to request just-in-time access to an organization role, such as **Write** or **Admin**, from the web and Slack
* Allow users to request membership of a resource group, at the role they need
* Set the right resource owners to delegate approvals to those with the most context
* Automatically revoke access when a time-bound grant expires

Opal connects to one Hugging Face organization through a fine-grained access token. To manage several organizations, add a Hugging Face app in Opal for each one.

## Supported resources

| Resource | Read | Grant and revoke access |
| - | - | - |
| Hugging Face organization roles | ✔️ | ✔️ (Revoke: Contributor, Write, and Admin) |
| Hugging Face resource groups (membership) | ✔️ | ✔️ |

Opal syncs members of your organization whose email Hugging Face shows to the token, and matches them to people in Opal by email. Hugging Face shows member emails only on Team and Enterprise plans, for members whose email matches a domain your organization has verified or set in its SSO configuration. Members without a visible email aren't synced.

The integration doesn't invite or remove organization members, and it doesn't sync repositories or collections. They inherit access from organization roles and resource groups.

### How Hugging Face access maps to Opal

* **Organization roles**: your organization appears in Opal as **Hugging Face Organization**, with the access levels **No access**, **Read**, **Contributor**, **Write**, and **Admin**. Each member holds one role, so requesting a different role replaces the existing one. Changing a member's role keeps their resource group memberships.
  * Revoking **Contributor**, **Write**, or **Admin** returns the user to **Read**. If the user no longer holds the revoked role, Opal leaves them as they are.
  * Opal doesn't revoke **Read** or **No access**, because that would mean removing the user from the organization. Remove users through your identity provider instead.
* **Resource groups**: each resource group appears in Opal as a **Hugging Face Resource Group**, with the access levels **Read**, **Contributor**, **Write**, **Admin**, and **Inherit**. **Inherit** gives the member the same role in the group as their organization role. Each group member holds one role, so requesting a different role on a group changes the existing one. Revoking a grant removes the user from the group.

### Limitations

* Resource groups and role changes require a Hugging Face Team or Enterprise plan. On other plans, Hugging Face rejects these calls, and no members sync because emails aren't shown.
* A user must already be a member of the organization before Opal can grant them a role or add them to a resource group.
* Because Opal can't revoke **Read** or **No access**, don't make those grants time-bound. Use time-bound access for **Contributor**, **Write**, and **Admin**, and for resource groups.

## Requirements

Before you begin, you must:

* Be an Opal Admin
* Be an **Admin** of the Hugging Face organization, on a Team or Enterprise plan

## Configuration steps

### 1. Create a fine-grained access token

Hugging Face's steps are in [User access tokens](https://huggingface.co/docs/hub/security-tokens).

1. In Hugging Face, go to your settings and open the [Access Tokens](https://huggingface.co/settings/tokens) tab.
2. Select **New token**, choose the **Fine-grained** token type, and name the token, for example `Opal`.
3. Scope the token's organization permissions to the organization you want Opal to manage, and give it read access to that organization's settings and members.
4. If Opal should change access, also select **Write access to organizations settings / member management** for that organization. Skip this if you'll set **Access** to **Read only** in step 2.
5. Create the token, then copy it. The token begins with `hf_`. You'll enter it in Opal in step 2.

The token acts as the user who created it, and it can only do what that user's organization role allows. If that user stops being an organization **Admin**, Opal can no longer change access.

> [!NOTE]
>
> If your organization requires administrator approval for fine-grained tokens, a token created by a non-admin stays **Pending** and Hugging Face rejects it with a `403` error. Tokens that organization admins create are approved automatically.

### 2. Create the Hugging Face app in Opal

In Opal, go to **Inventory** > **+ App** and select **Hugging Face**. Fill in the following fields:

![The Connect Hugging Face section of the Opal create-app form, with the Organization slug, Access, Resource groups, and Access token fields](https://mintcdn.com/opalsecurity/YjgTYcAChZTtguNV/images/docs/huggingface-create-app.png?fit=max\&auto=format\&n=YjgTYcAChZTtguNV\&q=85\&s=c32fdca75e0bfb9dc2e5396590a78fc8)

| Field | Value |
| - | - |
| App name | A name for the Hugging Face app in Opal, for example `Hugging Face`. |
| App admin | The owner who administers the app in Opal. |
| Description | A short description that helps requesters understand what this app is. |
| Visibility | Who in your organization can see the app. |
| Organization slug | The slug in your Hugging Face organization's URL. For `https://huggingface.co/acme`, the slug is `acme`. |
| Access | **Read and write** by default. Choose **Read only** to sync who has access without changing anything in Hugging Face. |
| Resource groups | **Sync** by default. Choose **Don't sync** to leave resource groups out of Opal. |
| Access token | The fine-grained token from step 1. |

You can change **Access** and **Resource groups** later, and replace the token, from the app's **Setup** tab. Changing **Resource groups** to **Don't sync** removes resource groups from Opal on the next sync. To manage a different organization, add another app.

### 3. Check the app setup

Opal doesn't test the token when you save the app. Open the app's **Setup** tab to check that the token can read your organization:

| Check | If it fails |
| - | - |
| Read members | Opal can't sync people or organization roles. Check **Organization slug**, and that the token has read access to the organization. |
| Read resource groups | Opal can't sync resource groups. The organization needs a Team or Enterprise plan. Shown only when **Resource groups** is **Sync**. |

Opal can't test write access from the **Setup** tab. A token without **Write access to organizations settings / member management** still looks healthy until a grant fails.

### 4. Import the organization and resource groups

After you save the app, import the items you want to manage: on the app's **Assets** tab, select **Import assets**, choose **Hugging Face Organization** and the resource groups, and turn on requests for them. Opal pulls access only for imported items, so roles and group members appear after the next sync.

## Troubleshooting

| What you see | What to do |
| - | - |
| **Read members** fails with a `401` error | Copy the token again and replace it on the **Setup** tab. |
| **Read members** fails with a `403` error | Check that the token is scoped to the organization and isn't **Pending** administrator approval. |
| **Read resource groups** fails with a `402` error | Resource groups need a Team or Enterprise plan. Upgrade the plan, or set **Resource groups** to **Don't sync**. |
| No accounts appear after a sync | Hugging Face shows member emails only on Team and Enterprise plans, for emails matching a verified organization domain or your SSO domains. Members without a visible email aren't synced. |
| An access change fails with a `402` or `403` error | Check that the organization is on a Team or Enterprise plan, that the token has **Write access to organizations settings / member management**, and that its creator is still an organization **Admin**. |
| An access change fails with a read-only error | **Access** is **Read only**. Change it to **Read and write** on the **Setup** tab. |
| Revoking **Read** or **No access** fails | Opal doesn't remove members from Hugging Face. Deprovision the user through your identity provider. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.