# Access issues for gated repos

**URL:** <https://discuss.huggingface.co/t/access-issues-for-gated-repos/103435>\
**Category:** Beginners\
**Created:** [August 22, 2024, 4:47am UTC](https://discuss.huggingface.co/t/access-issues-for-gated-repos/103435 "2024-08-22T04:47:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanchitamore](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sanchitamore](https://discuss.huggingface.co/u/sanchitamore)\
**Post date:** [August 22, 2024, 4:47am UTC](https://discuss.huggingface.co/t/access-issues-for-gated-repos/103435/1 "2024-08-22T04:47:42Z")

</div>

Hello Folks,

I am trying to use Mistral for a usecase on the hugging face mistral page I have raised a reuqest to get access to gated repo which I can see in my gated repos page now.

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/1/5/1510251dbc1b0cd0893193776aa05ef3e40223dd.png)

But the moment I try to access it on my local machine, it gives the below error -

`OSError: You are trying to access a gated repo. Make sure to have access to it at https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2. 401 Client Error. (Request ID: Root=1-66c6c127-582a274a30b062992d60c0e2;69f66232-83a8-449a-b7ba-b89f7176a5cd) Cannot access gated repo for url https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/resolve/main/config.json. Access to model mistralai/Mistral-7B-Instruct-v0.2 is restricted. You must be authenticated to access it.`

Can someone please help me understand why this can happen?

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/64626_2.png) [@mahmutc](https://discuss.huggingface.co/u/mahmutc)\
**Post date:** [August 22, 2024, 6:19am UTC](https://discuss.huggingface.co/t/access-issues-for-gated-repos/103435/2 "2024-08-22T06:19:33Z")

</div>

hi @sanchitamore

Did you create an access token? Did you add a permission for relevant repository?

You can check from [Hugging Face – The AI community building the future.](https://huggingface.co/settings/tokens).  
(Edit permissions → Repositories permissions)

Don’t forget to add `token` parameter when you call the function:

> **[User access tokens](https://huggingface.co/docs/hub/en/security-tokens)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

or use `huggingface-cli login`

> **[Gated models](https://huggingface.co/docs/hub/en/models-gated#access-gated-models-as-a-user)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![sanchitamore](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sanchitamore](https://discuss.huggingface.co/u/sanchitamore)\
**Post date:** [August 23, 2024, 10:01am UTC](https://discuss.huggingface.co/t/access-issues-for-gated-repos/103435/3 "2024-08-23T10:01:13Z")

</div>

Thanks @mahmutc.

I did add an access token and the permissions are set for the repositories.  
Access token currently has all permissions read & write.

I am able to successfully login through huggingface-cli login as well.

In the gated repositories it shows I have access to this repo.

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/4/b/4b0aac124b81779415769c9b7a9db45633c77bf4.png)

Can you please specify what should be the exact permissions for the same.

Here is my code snippet

```auto
from transformers import pipeline 

class LLM:
    def __init__ (self, model_name, auth_token=None):
        self.model = pipeline('text2text-generation', model=model_name, use_auth_token=auth_token)

    def predict(self, prompt, **kwargs):
        return self.model(text_inputs=prompt, **kwargs)[0]["generated_text"]

model = LLM(model_name="mistralai/Mistral-7B-Instruct-v0.3", auth_token="")

```

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/64626_2.png) [@mahmutc](https://discuss.huggingface.co/u/mahmutc)\
**Post date:** [August 23, 2024, 11:24am UTC](https://discuss.huggingface.co/t/access-issues-for-gated-repos/103435/4 "2024-08-23T11:24:13Z")

</div>

hi @sanchitamore  
This should work. In fact, if you log in, you don’t even need `token` parameter.

```auto
from transformers import pipeline 

class LLM:
    def __init__ (self, model_name, auth_token=None):
        self.model = pipeline('text2text-generation', model=model_name)

    def predict(self, prompt, **kwargs):
        return self.model(text_inputs=prompt, **kwargs)[0]["generated_text"]

model = LLM(model_name="mistralai/Mistral-7B-Instruct-v0.3")

```

Can you please run `huggingface-cli whoami` and double check repo permissions from [Hugging Face – The AI community building the future.](https://huggingface.co/settings/tokens) (Edit permissions → Repositories permissions)

You have to see repo name in the list:

 ![Screenshot from 2024-08-23 11-25-27](https://us1.discourse-cdn.com/hellohellohello/original/3X/1/7/17c641748ed2e417f42e693f73fad6692736e281.png)

It doesn’t matter whether you are logged in or not, this will work:

```auto
from transformers import pipeline 

class LLM:
    def __init__ (self, model_name, token=None):
        self.model = pipeline('text2text-generation', model=model_name, token=token)

    def predict(self, prompt, **kwargs):
        return self.model(text_inputs=prompt, **kwargs)[0]["generated_text"]

model = LLM(model_name="mistralai/Mistral-7B-Instruct-v0.3", token="your_token_should_be_here")

```
