> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monostate.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Configure API tokens and authentication

# Authentication

Configure authentication for Hugging Face Hub and W\&B.

## Hugging Face Token

### Environment Variable

```bash theme={null}
export HF_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxx"
```

### In Python

```python theme={null}
from autotrain.trainers.clm.params import LLMTrainingParams

params = LLMTrainingParams(
    model="google/gemma-3-270m",
    data_path="./data.jsonl",
    project_name="my-model",
    token="hf_xxxxxxxxxxxxxxxxxxxxx",  # HF token
)
```

### Getting a Token

1. Go to [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
2. Click "New token"
3. Select "Write" access for push to hub
4. Copy the token

## W\&B Token

### Environment Variable

```bash theme={null}
export WANDB_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```

### In Python

```python theme={null}
params = LLMTrainingParams(
    model="google/gemma-3-270m",
    data_path="./data.jsonl",
    project_name="my-model",
    log="wandb",
    wandb_token="xxxxxxxxxxxxxxxxxxxxxxxx",
)
```

### Getting a Token

1. Go to [wandb.ai/authorize](https://wandb.ai/authorize)
2. Copy your API key

## Push to Hub

To push models to Hugging Face Hub:

```python theme={null}
params = LLMTrainingParams(
    model="google/gemma-3-270m",
    data_path="./data.jsonl",
    project_name="my-model",
    push_to_hub=True,
    username="your-hf-username",
    token="hf_xxxxxxxxxxxxxxxxxxxxx",
)
```

## Private Models

Access private models with your token:

```python theme={null}
# Set environment variable
import os
os.environ["HF_TOKEN"] = "hf_xxxxxxxxxxxxxxxxxxxxx"

# Or pass directly
params = LLMTrainingParams(
    model="your-org/private-model",
    data_path="./data.jsonl",
    project_name="my-model",
    token="hf_xxxxxxxxxxxxxxxxxxxxx",
)
```

## Private Datasets

Access private datasets:

```python theme={null}
params = LLMTrainingParams(
    model="google/gemma-3-270m",
    data_path="your-org/private-dataset",  # HF dataset ID
    project_name="my-model",
    token="hf_xxxxxxxxxxxxxxxxxxxxx",
)
```

## Secure Token Handling

### Using .env Files

```bash theme={null}
# .env
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxx
WANDB_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
```

```python theme={null}
from dotenv import load_dotenv
import os

load_dotenv()

params = LLMTrainingParams(
    model="google/gemma-3-270m",
    data_path="./data.jsonl",
    project_name="my-model",
    token=os.getenv("HF_TOKEN"),
)
```

### Never Commit Tokens

Add to `.gitignore`:

```
.env
*.token
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Python SDK" href="/api/python-sdk">
    Full API reference
  </Card>

  <Card title="LLM Endpoints" href="/api/llm-endpoints">
    LLM training API
  </Card>
</CardGroup>
