# `HuggingfaceClient.Config`
[🔗](https://github.com/huggingface/huggingface_client/blob/v0.1.0/lib/huggingface_client/config.ex#L1)

HuggingFace Client configuration and environment variable management.

Manages all HuggingFace environment variables and runtime configuration,
mirroring the Python `huggingface_hub` environment variable system.

## Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `HF_TOKEN` | HuggingFace API token | (none) |
| `HUGGINGFACE_TOKEN` | Alias for HF_TOKEN | (none) |
| `HUGGING_FACE_HUB_TOKEN` | Legacy alias | (none) |
| `HF_HOME` | Base cache directory | `~/.cache/huggingface` |
| `HF_HUB_CACHE` | Hub cache directory | `$HF_HOME/hub` |
| `HF_ENDPOINT` | Hub endpoint URL | `https://huggingface.co` |
| `HF_HUB_DISABLE_SYMLINKS` | Disable symlinks in cache | (false) |
| `HF_HUB_OFFLINE` | Disable network requests | (false) |
| `HF_DATASETS_CACHE` | Datasets cache directory | `$HF_HOME/datasets` |
| `TRANSFORMERS_CACHE` | Transformers cache (legacy) | (none) |

## Elixir Config

    # config/config.exs
    config :huggingface_client,
      hub_url:       "https://huggingface.co",
      default_token: System.get_env("HF_TOKEN"),
      cache_dir:     System.get_env("HF_HUB_CACHE"),
      offline:       false

## Example

    # Get current token
    token = HuggingfaceClient.Config.token()

    # Get cache directory
    cache_dir = HuggingfaceClient.Config.cache_dir()

    # Check if offline mode is enabled
    if HuggingfaceClient.Config.offline?() do
      IO.puts("Offline mode: only using cached files")
    end

# `cache_dir`

```elixir
@spec cache_dir() :: String.t()
```

Returns the Hub cache directory.

Checks `HF_HUB_CACHE` env var, then `$HF_HOME/hub`.

# `datasets_cache_dir`

```elixir
@spec datasets_cache_dir() :: String.t()
```

Returns the datasets cache directory.

# `delete_token`

```elixir
@spec delete_token() :: :ok
```

Removes the locally saved token (equivalent to `huggingface-cli logout`).

# `disable_progress_bars?`

```elixir
@spec disable_progress_bars?() :: boolean()
```

Returns `true` if progress bars are disabled.

# `disable_symlinks?`

```elixir
@spec disable_symlinks?() :: boolean()
```

Returns `true` if symlinks in the cache are disabled.

# `endpoint`

```elixir
@spec endpoint() :: String.t()
```

Returns the Hub endpoint URL.

Checks `HF_ENDPOINT` env var, then application config, then default.

# `env_info`

```elixir
@spec env_info() :: map()
```

Returns a map of all HuggingFace-related environment variables that are set.

## Example

    env = HuggingfaceClient.Config.env_info()
    Enum.each(env, fn {k, v} -> IO.puts("#{k}=#{v}") end)

# `hf_home`

```elixir
@spec hf_home() :: String.t()
```

Returns the HuggingFace home directory.

Checks `HF_HOME` env var, then defaults to `~/.cache/huggingface`.

# `offline?`

```elixir
@spec offline?() :: boolean()
```

Returns `true` if offline mode is enabled.

In offline mode, no network requests are made — only cached files are used.
Controlled by `HF_HUB_OFFLINE` env var or application config.

# `print_info`

```elixir
@spec print_info() :: :ok
```

Prints the current configuration to stdout.

## Example

    HuggingfaceClient.Config.print_info()

# `save_token`

```elixir
@spec save_token(String.t()) :: :ok | {:error, term()}
```

Saves a token to the local credential file (`~/.cache/huggingface/token`).

This is equivalent to running `huggingface-cli login`.

## Example

    HuggingfaceClient.Config.save_token("hf_your_token")

# `token`

```elixir
@spec token() :: String.t() | nil
```

Returns the configured HuggingFace API token.

Checks in order:
1. Application config: `config :huggingface_client, default_token: "hf_xxx"`
2. `HF_TOKEN` env var
3. `HUGGINGFACE_TOKEN` env var
4. `HUGGING_FACE_HUB_TOKEN` env var (legacy)
5. Token saved on disk by `huggingface-cli login` at `~/.cache/huggingface/token`

Returns `nil` if no token is found.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
