Home Blog Contact
Home/Blog/How to Access and Use Gated Models on Hugging…
How toLLM EngineeringHugging FaceGated ModelsAuthentication

How to Access and Use Gated Models on Hugging Face

9 min readBy Miloš Mitrović

A gated model on Hugging Face is one where the author has turned on access requests, so you must agree to share your contact information before you can download the files. The short version: log in, open the model page in your browser, click the agree button to request access, wait for approval (often instant), then create a user token and authenticate your environment so from_pretrained can pull the weights. This guide covers the full path from access request to a working from_pretrained call, plus the errors you will hit and how to clear them.

Key takeaways

  • The short answer: request access in the browser on the model page, get approved, create a Hugging Face token, run hf auth login or set HF_TOKEN, then load with from_pretrained("org/model", token=...).
  • Requesting access is browser-only. You cannot request access through the API or a script. The API exists only for authors managing incoming requests.
  • Access is always granted to an individual user, never to an organization. Even org members are approved one account at a time.
  • The token role alone is not enough. The account behind the token must also have been granted access on the model page.
  • The current CLI is hf, not huggingface-cli. The current keyword is token=, not use_auth_token=.
  • Authors keep complete control and can revoke access at any time, even after approval and even in automatic-approval mode.

What a gated model is, and what you need first

Gating gives model authors control over how their weights are used, and it is common for early research releases and for models with licence terms attached. When you open a gated model page you do not see the usual file listing. Instead you see a form telling you that you need to agree to share your contact information. Hugging Face is the hub for open-source model sharing, and many of the most useful open-weight releases, including several Llama and Hermes families, ship through a gate.

Before you start, make sure you have:

  • A Hugging Face user account, logged in.
  • Python with huggingface_hub and transformers installed if you plan to load the model in code.
  • A few minutes, since some models use manual approval that is not instant.
pip install --upgrade huggingface_hub transformers

How to access and use a gated model: the steps

  1. Open the model page while logged in. Go to the model on the Hub (for example https://huggingface.co/org/gated-model). If it is gated you will see a prompt to share your contact information instead of the file list.
  2. Request access and accept the terms. The gate shows a form. Click the button labelled Agree and send request to access repo. Clicking Agree does two things at once: it shares your username and email with the author, and where the author has attached licence terms it records your acceptance of them. It is one gate, not two separate steps. If the author added extra fields (company, country, intended use), fill them in as completely as you can, since that is what the author reviews.
    • Automatic approval: you get access to the files immediately.
    • Manual approval: the request sits pending until the author accepts it, which can take longer.
  3. Confirm you were approved. Reload the model page. Once approved, the normal file listing appears. If you see a message that your request was rejected, you cannot access the repo and, if you were rejected from the pending list, you cannot request again.
  4. Create a user token. Go to https://huggingface.co/settings/tokens and create a token. For production, prefer a fine-grained token scoped to read access on just that one model, so a leak has minimal blast radius. A plain read token also works for downloading. Create one token per machine or app so you can revoke it independently.
  5. Authenticate your environment. Pick whichever fits your workflow. All three make the token available to the Hugging Face libraries.

    CLI login (interactive browser device flow, or paste the token):

    hf auth login

    Environment variable (takes priority over the token saved on disk):

    export HF_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

    From Python:

    from huggingface_hub import login
    import os
    
    login(token=os.environ["HF_TOKEN"])

    Confirm the identity that is actually authenticated:

    hf auth whoami
  6. Load the model. If you already ran hf auth login or set HF_TOKEN, the token is picked up implicitly and you can omit it:
    from transformers import AutoModelForCausalLM, AutoTokenizer
    
    tokenizer = AutoTokenizer.from_pretrained("org/gated-model")
    model = AutoModelForCausalLM.from_pretrained("org/gated-model")

    Or pass the token explicitly, for example when reading it from a secret store:

    import os
    from transformers import AutoModelForCausalLM, AutoTokenizer
    
    access_token = os.environ["HF_TOKEN"]  # do not hardcode secrets
    
    tokenizer = AutoTokenizer.from_pretrained("org/gated-model", token=access_token)
    model = AutoModelForCausalLM.from_pretrained("org/gated-model", token=access_token)

That is the whole task. The sections below add the authentication detail and cover what breaks.

Authentication and token detail

The token is what lets scripts, containers, and servers download files you have been granted. Two points matter most for gated access.

The account must have access, not just the token. A valid token authenticates you as its owner. If that owner has not been granted access on the model page, the download still fails. For a production service, have a team member request and receive access on the model, then mint a fine-grained token on that same account scoped to read the model.

Use the current names. The tooling was renamed, and older tutorials use commands that are now deprecated:

Old (deprecated)Current
huggingface-cli loginhf auth login
huggingface-cli whoami / logouthf auth whoami / hf auth logout
from_pretrained(..., use_auth_token=...)from_pretrained(..., token=...)
HUGGING_FACE_HUB_TOKENHF_TOKEN

Other useful auth commands:

hf auth login --force    # re-login or switch tokens
hf auth switch           # pick among multiple saved tokens
hf auth list             # list saved tokens on this machine
hf auth logout

In hosted environments, set HF_TOKEN as a Space secret or a Google Colab secret and the libraries authenticate automatically. Full details are in the Hugging Face security tokens documentation.

Troubleshooting common errors

  • 401 Unauthorized or no token found. The environment is not authenticated. Run hf auth login, or export HF_TOKEN, and confirm with hf auth whoami. If you set HF_TOKEN, remember it overrides the token stored on disk, so a stale env var can mask a good saved token.
  • 403 Forbidden or GatedRepoError. The token is valid but the account behind it has not been granted access, or the request is still pending. Open the model page as that account and confirm the file list is visible. If a colleague requested access, make sure the token belongs to that same account, since access is per individual.
  • Request still pending. The model uses manual approval and the author has not accepted yet. There is no API to accelerate this. Wait, or check whether the model page shows your request as pending or rejected.
  • Rejected and cannot re-request. Rejection is sticky. A user rejected from the pending list cannot submit another request for that repo.
  • Worked yesterday, fails today. Authors can revoke access at any time without notice, even after approval and even under automatic approval. Re-check your access on the model page.
  • 403 against an organization's resources with a valid read token. Some Team and Enterprise orgs enforce a fine-grained-only policy. Mint a fine-grained token scoped to the specific resource instead of a broad read or write token.

What to do next

Once the weights download, the usual next steps are experiment, run locally, then serve.

  • Experiment in Python. The Transformers model loading docs cover from_pretrained, device_map="auto" for large models, dtype, and sharding.
  • Run it locally with no infrastructure. Install Ollama and follow the Ollama quickstart to run a model on a laptop with an OpenAI-compatible API on localhost:11434.
  • Serve it for throughput. Stand up an OpenAI-compatible endpoint with the vLLM quickstart, or deploy as a container with Text Generation Inference. For gated weights in TGI, the "why won't it download" fix is to pass your token, covered in the TGI gated model access guide.
  • Read the licence before you ship. Gated does not mean unrestricted. The Llama 4 Community License is a good example, with obligations such as displaying "Built with Llama," prefixing derived model names, and a commercial-licence clause above a monthly-active-user threshold.

If you are weighing whether to pursue open weights at all, the case is largely about control and cost. See why enterprises are moving to open-weight models, and the economics of running open-weight models for routine workloads instead of paying per API call.

Sources

M
Miloš Mitrović
Email Marketing for Ecommerce

Have a question or a project?

Whether it is about this post or a system you want built, I'm happy to talk.

Get in touch

404

Post not found. It may have been moved or the link is incorrect.

← Back to the blog
Summarize with AI
ChatGPT, Perplexity, and Grok open with the prompt ready to run. Claude, Gemini, and Copilot open a chat with the prompt copied; press Ctrl+V (Cmd+V on Mac) to paste. The full text is included, so it works even without web access.