Persistent 401 Unauthorized Error on Gated Models

Hello,

I am getting a persistent 401 Unauthorized error in Google Colab when trying to download any gated model, such as meta-llama/Meta-Llama-3-8B-Instruct.

I have already confirmed on the model’s webpage that I have been granted access. The error continues even after I generate a brand new write token and pass it directly to the from_pretrained function in my code.

This suggests a possible issue with my account’s token validation, as all standard debugging steps have failed. Could you please advise?

Thank you.

1 Like

First, try whoami-v2, which should make verification easy.

Hello,

Following up on my 401 Unauthorized issue. I have run the command-line diagnostic tool as requested.

When I run huggingface-cli whoami, I get the following explicit error:

Invalid user token. The token from HF_TOKEN environment variable is invalid.{"error":"Invalid credentials in Authorization header"}

I have meticulously regenerated and pasted a new write token multiple times, and the error persists. This definitively proves the problem is not with my code but with the token validation for my account. Can you please investigate the status of my account and tokens?

Thank you.

1 Like

If the problem is account-specific, I think it would be quicker to contact Hugging Face support. website@huggingface.co
Another case that occasionally occurs is that extra information is added when copying and pasting tokens. This is more likely to happen when using shortcut keys.
In addition, there are many conditions that cause a 401 error.

1 Like