hf spaces secrets and variables add, list, and delete
Introduced 2026-05-06 · score 0.96
HOW TO USE IT
When setting or inspecting a Space’s environment values, use `hf spaces secrets` for write-only secrets and `hf spaces variables` for readable variables. Add values with repeated `-s`/`-e` or the corresponding file option, list them with `ls`, and delete a key with `--yes` to skip confirmation.
hf spaces secrets ls <owner>/<space>
hf spaces secrets add <owner>/<space> -s <KEY>=<VALUE> -s <KEY>=<VALUE>
hf spaces secrets add <owner>/<space> --secrets-file <path>
hf spaces secrets delete <owner>/<space> <KEY> --yeshf spaces variables ls <owner>/<space>
hf spaces variables add <owner>/<space> -e <KEY>=<VALUE> -e <KEY>=<VALUE>
hf spaces variables add <owner>/<space> --env-file <path>
hf spaces variables delete <owner>/<space> <KEY> --yesfrom huggingface_hub import HfApi
api = HfApi()
secrets = api.get_space_secrets(repo_id="<owner>/<space>")WHY THIS HELPS
Set or inspect a Space’s environment values while developing or maintaining its code.
REQUIREMENTS AND LIMITATIONS
- Version: v1.14.0
- SPACE_ID (required): Space ID, such as `<owner>/<space>`.
- KEY (required): Name of the secret or variable to remove.
- -s, --secrets: Set secret environment variables; accepts a key-value pair or a key whose value is read from the environment. Repeat to set multiple secrets.
- --secrets-file: Read secret environment variables from a file.
- -e, --env: Set environment variables using `KEY=VALUE`; repeat to set multiple variables.
- --env-file: Read environment variables from a file.
- -y, --yes: Automatically answer Yes to the delete confirmation prompt.
- --token: User Access Token for Hub authentication.
- repo_id (required): Space ID passed to `HfApi.get_space_secrets()`.
- Prerequisite: For CLI token authentication, `--token` accepts a User Access Token.
- Secret values are write-only and cannot be read back; listing returns keys, descriptions, and update timestamps.
- Variables are readable.
- The source gives `-env-file` in the release summary and `--env-file` in the CLI documentation.
- Docs conflict: The release summary says `-env-file`; v1.14.0 CLI docs document `--env-file` for variables.
FIRST-PARTY EVIDENCE
- https://github.com/huggingface/huggingface_hub/releases/tag/v1.14.0
- https://github.com/huggingface/huggingface_hub/pull/4170
- https://github.com/huggingface/huggingface_hub/pull/4182
- https://github.com/huggingface/huggingface_hub/blob/v1.14.0/docs/source/en/guides/cli.md
- https://github.com/huggingface/huggingface_hub/blob/v1.14.0/docs/source/en/guides/manage-spaces.md
- https://github.com/huggingface/huggingface_hub/blob/v1.14.0/docs/source/en/package_reference/cli.md
Check the installed version and the source before using it. Entry JSON