Skip to contents

Utility helper to manage the `HF_TOKEN` environment variable used for authenticated downloads from Hugging Face. The token is set for the current R session, and it can optionally be persisted to a `.Renviron` file for future sessions. The token is not printed back to the console.

Usage

set_hf_token(token, persist = FALSE, renviron_path = NULL)

Arguments

token

Character scalar. Your Hugging Face access token, typically starting with `hf_`.

persist

Logical flag controlling whether to persist the token to a startup file. Defaults to `FALSE`.

renviron_path

Optional path to the `.Renviron` file to update when `persist = TRUE`. Must be supplied explicitly when persisting.

Value

Invisibly returns the currently active token value.

Examples

if (FALSE) { # \dontrun{
set_hf_token("hf_xxx")
tmp_env <- file.path(tempdir(), ".Renviron_localLLM")
set_hf_token("hf_xxx", persist = TRUE, renviron_path = tmp_env)
} # }