Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

feat: add --offline and --disable-partner-nodes, deprecate --disable-api-nodes (#16672)

Deep Mehta170594057a22
diff --git a/.ci/windows_nvidia_base_files/advanced/run_nvidia_gpu_disable_api_nodes.bat b/.ci/windows_nvidia_base_files/advanced/run_nvidia_gpu_disable_api_nodes.bat
index 4501ef9a1..1bcab0f26 100644
--- a/.ci/windows_nvidia_base_files/advanced/run_nvidia_gpu_disable_api_nodes.bat
+++ b/.ci/windows_nvidia_base_files/advanced/run_nvidia_gpu_disable_api_nodes.bat
@@ -1,3 +1,3 @@
-..\python_embeded\python.exe -s ..\ComfyUI\main.py --windows-standalone-build --disable-api-nodes
+..\python_embeded\python.exe -s ..\ComfyUI\main.py --windows-standalone-build --offline
echo If you see this and ComfyUI did not start try updating your Nvidia Drivers to the latest. If you get a c10.dll error you need to install vc redist that you can find: https://aka.ms/vc14/vc_redist.x64.exe
pause
diff --git a/README.md b/README.md
index 1f3fc630f..a6b57ecfe 100644
--- a/README.md
+++ b/README.md
@@ -78,7 +78,7 @@ See what ComfyUI can do with the [newer template workflows](https://comfy.org/wo
- Load complete checkpoints or separate diffusion models, VAEs, text encoders, LoRAs, ControlNets, adapters, and upscalers from supported model formats.
- Built-in tools for inpainting, outpainting, reference conditioning, masks and compositing, model merging, upscaling, frame interpolation, segmentation, depth estimation, and media processing.
- Save and load workflows as JSON, or recover complete workflows and seeds from supported generated media.
-- Runs fully offline: core does not download anything unless you request it. Use `--disable-api-nodes` to disable the optional paid [Comfy API nodes](https://docs.comfy.org/tutorials/api-nodes/overview) and force all built-in functionality to stay offline.
+- Runs fully offline: core does not download anything unless you request it. Use `--offline` to disable the optional paid [Comfy API nodes](https://docs.comfy.org/tutorials/api-nodes/overview) and force all built-in functionality to stay offline, or `--disable-partner-nodes` to only disable the API nodes.
- Extend ComfyUI with custom nodes
- Configure additional model locations with [`extra_model_paths.yaml`](extra_model_paths.yaml.example).
- Support for saving and loading high bit depth images and videos: 16 bit PNG images, 32 bit EXR, 10 bit AVIF are supported and more.
diff --git a/comfy/cli_args.py b/comfy/cli_args.py
index ba89699d6..c4956e807 100644
--- a/comfy/cli_args.py
+++ b/comfy/cli_args.py
@@ -214,7 +214,9 @@ parser.add_argument("--windows-standalone-build", action="store_true", help="Win
parser.add_argument("--disable-metadata", action="store_true", help="Disable saving prompt metadata in files.")
parser.add_argument("--disable-all-custom-nodes", action="store_true", help="Disable loading all custom nodes.")
parser.add_argument("--whitelist-custom-nodes", type=str, nargs='+', default=[], help="Specify custom node folders to load even when --disable-all-custom-nodes is enabled.")
-parser.add_argument("--disable-api-nodes", action="store_true", help="Disable loading all api nodes. Also prevents the frontend from communicating with the internet.")
+parser.add_argument("--disable-partner-nodes", action="store_true", help="Disable loading partner nodes (the paid API nodes). The frontend keeps its internet access.")
+parser.add_argument("--offline", action="store_true", help="Prevent the frontend from communicating with the internet by setting a restrictive Content-Security-Policy header. Also disables partner nodes.")
+parser.add_argument("--disable-api-nodes", action="store_true", help="Deprecated alias for --offline. Use --offline, or --disable-partner-nodes to only disable partner nodes.")
parser.add_argument("--multi-user", action="store_true", help="Enables per-user storage.")
@@ -291,6 +293,12 @@ if args.high_ram:
if args.windows_standalone_build:
args.auto_launch = True
+if args.disable_api_nodes:
+ args.offline = True
+
+if args.offline:
+ args.disable_partner_nodes = True
+
if args.disable_auto_launch:
args.auto_launch = False
diff --git a/main.py b/main.py
index af82e3103..92cad0420 100644
--- a/main.py
+++ b/main.py
@@ -52,6 +52,9 @@ if __name__ == "__main__":
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
logging.warning("On windows we are currently forcing single GPU mode in ComfyUI due to a Nvidia related issue, if you want to disable this use: --cuda-device all")
+ if args.disable_api_nodes:
+ logging.warning("--disable-api-nodes is deprecated and will be removed in a future version. It currently behaves like --offline. Use --offline to keep the frontend offline, or --disable-partner-nodes to only disable partner nodes.")
+
faulthandler.enable(file=sys.stderr, all_threads=args.debug_hang)
if __name__ == "__main__" and args.debug_hang:
dumping_traceback = False
@@ -525,7 +528,7 @@ def start_comfyui(asyncio_loop=None):
hook_breaker_ac10a0.save_functions()
asyncio_loop.run_until_complete(nodes.init_extra_nodes(
init_custom_nodes=(not args.disable_all_custom_nodes) or len(args.whitelist_custom_nodes) > 0,
- init_api_nodes=not args.disable_api_nodes
+ init_api_nodes=not args.disable_partner_nodes
))
# Re-apply Comfy's cuDNN benchmark policy after custom-node imports. Benchmark
diff --git a/server.py b/server.py
index de0076a76..ba951d688 100644
--- a/server.py
+++ b/server.py
@@ -242,7 +242,7 @@ class PromptServer():
else:
middlewares.append(create_origin_only_middleware())
- if args.disable_api_nodes:
+ if args.offline:
middlewares.append(create_block_external_middleware())
if args.enable_manager:
diff --git a/tests-unit/server_test/test_offline_flag.py b/tests-unit/server_test/test_offline_flag.py
new file mode 100644
index 000000000..b7b875157
--- /dev/null
+++ b/tests-unit/server_test/test_offline_flag.py
@@ -0,0 +1,55 @@
+"""Tests for --offline, --disable-partner-nodes and the deprecated --disable-api-nodes"""
+
+import subprocess
+import sys
+from unittest.mock import MagicMock
+
+import pytest
+from aiohttp import web
+from aiohttp.test_utils import TestClient, TestServer
+
+from comfy.cli_args import args
+import server
+
+
+async def pong(request):
+ return web.Response(text="pong")
+
+
+def parse_args(*argv):
+ code = (
+ "import comfy.options; comfy.options.enable_args_parsing(); from comfy.cli_args import args; "
+ "print(args.offline, args.disable_partner_nodes, args.disable_api_nodes)"
+ )
+ out = subprocess.run([sys.executable, "-c", code, *argv], capture_output=True, text=True, check=True)
+ return out.stdout.split()[-3:]
+
+
[email protected]("argv,expected", [
+ ([], ["False", "False", "False"]),
+ (["--disable-partner-nodes"], ["False", "True", "False"]),
+ (["--offline"], ["True", "True", "False"]),
+ (["--disable-api-nodes"], ["True", "True", "True"]),
+ (["--disable-partner-nodes", "--offline"], ["True", "True", "False"]),
+])
+def test_arg_parsing(argv, expected):
+ assert parse_args(*argv) == expected
+
+
[email protected]("offline,expect_csp", [
+ (False, False),
+ (True, True),
+])
+async def test_csp_header(monkeypatch, offline, expect_csp):
+ monkeypatch.setattr(args, "offline", offline)
+ prompt_server = server.PromptServer(None, MagicMock(enabled=False))
+ prompt_server.app.router.add_get("/ping", pong)
+ async with TestClient(TestServer(prompt_server.app)) as client:
+ resp = await client.get("/ping")
+ assert resp.status == 200
+ csp = resp.headers.get("Content-Security-Policy")
+ if expect_csp:
+ assert "connect-src 'self' data:" in csp
+ else:
+ assert csp is None