# Unable to access public model - status 401

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%3E%5C
**Category:** Models\
**Created:** [March 8, 2025, 9:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806 "2025-03-08T21:09:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hany3210](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/hany3210/32/42833_2.png) [@Hany3210](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHany3210)%5C
**Post date:** [March 8, 2025, 9:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F1 "2025-03-08T21:09:29Z")

</div>

i build .net code to access sentence-transformers/all-MiniLM-L6-v2.  
while running, i get the following error:  
{StatusCode: 401, Unauthorized]

although token is right , it has read permission  
using (var client = new HttpClient())  
{  
client.DefaultRequestHeaders.Add(“Authorization”, “hf\_DimrceBJNUZfMjpICMAQfXzNkrioZErQVI”);

```
var requestContent = new
{
    inputs = new string[] { text1, text2 }
};

var response = await client.PostAsync("/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fsentence-transformers%2Fall-MiniLM-L6-v2",
    new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(requestContent), Encoding.UTF8, "application/json"));

if (!response.IsSuccessStatusCode)
{
    Console.WriteLine("Error: " + response.ReasonPhrase);
    return -1;
}

```

}

appreciate your support

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 9, 2025, 5:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F2 "2025-03-09T05:06:17Z")

</div>

If you are getting a 401 error even though the token is correct, it is usually because of a network setting such as SSL, or because a different token that has been cached is being used somewhere.

If it is a completely server error, I think it is more likely that a non-401 error will be displayed.

> [@Error 401 Client Error: Unauthorized for url](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-401-client-error-unauthorized-for-url%2F19714)%3A
>
> When using model card of my private speech recognition model with LM, I got this error: 401 Client Error: Unauthorized for url: [https://huggingface.co/api/models/taliai/tali-asr-with-lm/revision/main](https://huggingface.co/api/models/taliai/tali-asr-with-lm/revision/main) while the same model without lm works fine. Is there anything wrong on my model or model card or … Any help is appreciated.

> [@Assistance with 401 Unauthorized Error for API Access](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fassistance-with-401-unauthorized-error-for-api-access%2F128643)%3A
>
> I am currently encountering an issue while attempting to use the Hugging Face Inference API with access tokens. Despite following all documentation and testing multiple configurations, I am consistently receiving a 401 Unauthorized error when calling the /models endpoint. Here is a summary of the steps I have taken to troubleshoot this issue: I generated both read-only and fine-grained tokens from my account settings. I ensured the tokens include permissions for: Making calls to the serverl…

---

<div class="post-metadata">

**Author:** ![Hany3210](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/hany3210/32/42833_2.png) [@Hany3210](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHany3210)%5C
**Post date:** [March 9, 2025, 1:38pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F3 "2025-03-09T13:38:50Z")

</div>

i checked links you put, but i already assure that token is working fine, this is public repository

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 9, 2025, 1:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F4 "2025-03-09T13:54:03Z")

</div>

If you access the public repo, with a token, you may get an error.

I think the way tokens are handled has changed recently, and the timing and conditions for getting an error have changed a little…

---

<div class="post-metadata">

**Author:** ![Hany3210](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/hany3210/32/42833_2.png) [@Hany3210](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHany3210)%5C
**Post date:** [March 10, 2025, 5:55am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F5 "2025-03-10T05:55:38Z")

</div>

do you mean that i have to subscribe for one of plan so that i can get access ?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 10, 2025, 6:16am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F6 "2025-03-10T06:16:10Z")

</div>

Even if you don’t have a paid plan, you should be able to use that model.

Oh no, you’ve leaked a token.😱 I’ve just noticed. You should invalidate that token. You can create as many tokens as you like, so there’s no need to worry, but it’s dangerous to leave a leaked token alone.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 10, 2025, 6:41am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F7 "2025-03-10T06:41:30Z")

</div>

I tried it out a bit. To cut a long story short, none of the inference APIs for sentence\_similarity work properly. It doesn’t work with or without tokens, or with or without the header itself. It just doesn’t work.

```py
HF_TOKEN = "hf_my_valid_pro_token"

import requests

API_URL = "/static-proxy?url=https%3A%2F%2Frouter.huggingface.co%2Fhf-inference%2Fv1"
headers = {"Authorization": f"Bearer {HF_TOKEN}"}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()
    
output = query({
    "inputs": {
    "source_sentence": "That is a happy person",
    "sentences": [
        "That is a happy dog",
        "That is a very happy person",
        "Today is a sunny day"
    ]
},
})

print(output)
# {'error': 'Not allowed to POST v1 for provider hf-inference'}

from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="hf-inference",
    api_key=HF_TOKEN
)

result = client.sentence_similarity(
    model="sentence-transformers/all-MiniLM-L6-v2",
    #model="BAAI/bge-m3", # 503 error
    #model="Qodo/Qodo-Embed-1-1.5B", # 503 error
    sentence="That is a happy person",
    other_sentences=[
        "That is a happy dog",
        "That is a very happy person",
        "Today is a sunny day"
    ],
)

print(result)
#Bad request:
#Input should be a valid dictionary or instance of SentenceSimilarityInputsCheck: received `None` in `parameters`

```

---

<div class="post-metadata">

**Author:** ![Hany3210](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/hany3210/32/42833_2.png) [@Hany3210](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHany3210)%5C
**Post date:** [March 12, 2025, 8:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funable-to-access-public-model-status-401%2F144806%2F8 "2025-03-12T20:54:00Z")

</div>

I cut it short but on another way.  
i made semantic similarity work in python , then call it from .net using REST.  
it works fine now 🙂
