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: falseExample
# 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
Summary
Functions
Returns the Hub cache directory.
Returns the datasets cache directory.
Removes the locally saved token (equivalent to huggingface-cli logout).
Returns true if progress bars are disabled.
Returns true if symlinks in the cache are disabled.
Returns the Hub endpoint URL.
Returns a map of all HuggingFace-related environment variables that are set.
Returns the HuggingFace home directory.
Returns true if offline mode is enabled.
Prints the current configuration to stdout.
Saves a token to the local credential file (~/.cache/huggingface/token).
Returns the configured HuggingFace API token.
Functions
@spec cache_dir() :: String.t()
Returns the Hub cache directory.
Checks HF_HUB_CACHE env var, then $HF_HOME/hub.
@spec datasets_cache_dir() :: String.t()
Returns the datasets cache directory.
@spec delete_token() :: :ok
Removes the locally saved token (equivalent to huggingface-cli logout).
@spec disable_progress_bars?() :: boolean()
Returns true if progress bars are disabled.
@spec disable_symlinks?() :: boolean()
Returns true if symlinks in the cache are disabled.
@spec endpoint() :: String.t()
Returns the Hub endpoint URL.
Checks HF_ENDPOINT env var, then application config, then default.
@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)
@spec hf_home() :: String.t()
Returns the HuggingFace home directory.
Checks HF_HOME env var, then defaults to ~/.cache/huggingface.
@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.
@spec print_info() :: :ok
Prints the current configuration to stdout.
Example
HuggingfaceClient.Config.print_info()
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")
@spec token() :: String.t() | nil
Returns the configured HuggingFace API token.
Checks in order:
- Application config:
config :huggingface_client, default_token: "hf_xxx" HF_TOKENenv varHUGGINGFACE_TOKENenv varHUGGING_FACE_HUB_TOKENenv var (legacy)- Token saved on disk by
huggingface-cli loginat~/.cache/huggingface/token
Returns nil if no token is found.