You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add support for CIVITAI_TOKEN and HF_TOKEN environment variables
Closes#280.
Adds support for the standardized Hugging Face and CivitAI API token environment variables.
This provides a safe and easy way to provide transient secrets without leaking them to disk (nothing gets written to the config).
It also makes it much easier to integrate Comfy-CLI with scripting, since the user no longer has to infinitely provide the "--set-X-token" flags every single time they run the command anymore (which they had to do in the past, just to be sure that the latest token was always used).
The order of priority is `--set-X-token`, then the environment variables (if they exist), and lastly the static config fallback values.
This new feature is now documented in the README and in various error messages.
The code has also been refactored, and the error messages have been improved for clarity and consistency.
- URL: CivitAI page, Hugging Face file URL, etc...
179
+
- You can also specify your API tokens via the `CIVITAI_API_TOKEN` and `HF_API_TOKEN` environment variables. The order of priority is `--set-X-token` (always highest priority), then the environment variables if they exist, and lastly your config's stored tokens from previous `--set-X-token` usage (which remembers your most recently set token values).
180
+
- Tokens provided via the environment variables are never stored persistently in your config file. They are intended as a way to easily and safely provide transient secrets.
"Unauthorized access to Hugging Face model. Please set the HuggingFace API token using --set-hf-api-token"
279
+
f"Unauthorized access to Hugging Face model. Please set the Hugging Face API token using `comfy model download --set-hf-api-token` or via the `{constants.HF_API_TOKEN_ENV_KEY}` environment variable"
Copy file name to clipboardExpand all lines: comfy_cli/file_utils.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
importhttpx
8
8
importrequests
9
9
10
-
fromcomfy_cliimportui
10
+
fromcomfy_cliimportconstants, ui
11
11
12
12
13
13
classDownloadException(Exception):
@@ -36,7 +36,7 @@ def parse_json(input_data):
36
36
msg_json=parse_json(message)
37
37
ifmsg_jsonisnotNone:
38
38
if"message"inmsg_json:
39
-
returnf"Unauthorized download ({status_code}).\n{msg_json['message']}\nor you can set civitai api token using `comfy model download --set-civitai-api-token <token>`"
39
+
returnf"Unauthorized download ({status_code}).\n{msg_json['message']}\nor you can set a CivitAI API token using `comfy model download --set-civitai-api-token` or via the `{constants.CIVITAI_API_TOKEN_ENV_KEY}` environment variable"
40
40
returnf"Unauthorized download ({status_code}), you might need to manually log into a browser to download this"
41
41
elifstatus_code==403:
42
42
returnf"Forbidden url ({status_code}), you might need to manually log into a browser to download this"
0 commit comments