# Accessing Private/Gated Models

## Accessing Private/Gated Models

Due to the possibility of leaking access tokens to users of your website or web application, we only support accessing private/gated models from server-side environments (e.g., Node.js) that have access to the process’ environment variables.

### Step 1: Generating a User Access Token

[User Access Tokens](https://huggingface.co/docs/hub/security-tokens) are the preferred way to authenticate an application to BOINC AI services.

To generate an access token, navigate to the [Access Tokens tab](https://huggingface.co/settings/tokens) in your settings and click on the **New token** button. Choose a name for your token and click **Generate a token** (we recommend keeping the “Role” as read-only). You can then click the **Copy** button next to your newly-created token to copy it to your clipboard.

<figure><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/new-token.png" alt=""><figcaption></figcaption></figure>

To delete or refresh User Access Tokens, you can click the **Manage** button.

### Step 2: Using the access token in Transformers.js

Transformers.js will attach an Authorization header to requests made to the BOINC AI Hub when the `BA_ACCESS_TOKEN` environment variable is set and visible to the process.

One way to do this is to call your program with the environment variable set. For example, let’s say you have a file called `llama.js` with the following code:

Copied

```
import { AutoTokenizer } from '@xenova/transformers';

// Load tokenizer for a gated repository.
const tokenizer = await AutoTokenizer.from_pretrained('meta-llama/Llama-2-7b-ba');

// Encode text.
const text = 'Hello world!';
const encoded = tokenizer.encode(text);
console.log(encoded);
```

You can then use the following command to set the `BA_ACCESS_TOKEN` environment variable and run the file:

Copied

```
BA_ACCESS_TOKEN=ba_... node tests/llama.js
```

(remember to replace `ba_...` with your actual access token).

If done correctly, you should see the following output:

Copied

```
[ 1, 15043, 3186, 29991 ]
```

Alternatively, you can set the environment variable directly in your code:

Copied

```
// Set access token (NB: Keep this private!)
process.env.BA_ACCESS_TOKEN = 'ba_...';

// ... rest of your code
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boinc-ai.gitbook.io/transformers.js/developer-guides/accessing-private-gated-models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
