Network / downloads

HuggingFace: 403 Forbidden when downloading a gated model

401 Client Error: Unauthorized for url: https://huggingface.co/...
By Fredoline Eruo · Last verified May 6, 2026

Cause

Gated models (Llama, Gemma) require accepting the license on the HuggingFace website AND providing your access token to download. A 401/403 means one of those two is missing.

Solution

1. Accept the license on the model page. Visit the model URL (e.g., huggingface.co/meta-llama/Llama-3.1-8B-Instruct) while signed in to your HF account. Click "Acknowledge license" / "Submit access request". For Llama, approval is usually instant; for some research models it takes hours.

2. Get a HuggingFace token at huggingface.co/settings/tokens. "Read" scope is enough for downloads.

3. Authenticate locally:

# CLI login (saves to ~/.cache/huggingface)
hf auth login
# or, set env var per session
export HF_TOKEN="hf_xxxxxxxxxxxxx"

4. Re-run your download. hf download, transformers from_pretrained, and Ollama (when pulling from HF) all pick up the token automatically.

Alternative for Llama specifically: Use Ollama's hosted version (ollama pull llama3.1:8b) — Meta has a separate license arrangement with Ollama so no HF account is required.

Related errors

Did this fix it?

If your case was different, email hello@runlocalai.co with what you saw and we'll update the page. If it worked but took different commands on your platform, we want to know that too.