Skip to content

Commit e7fbb3c

Browse files
Add deploy environment header to partner node API calls
Read a .comfy_environment file from the ComfyUI base directory to determine the deployment environment (e.g. standalone, portable, desktop). Defaults to 'local_git' when the file is absent. The value is sent as an X-Comfy-Deploy-Env header on all requests to api.comfy.org, allowing the API to differentiate between environment types. The .comfy_environment file is gitignored so launchers/installers can write it without affecting the repository. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d939e-6b4d-738b-8d1a-ac7cbf6736a4
1 parent 1de83f9 commit e7fbb3c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ web_custom_versions/
2424
openapi.yaml
2525
filtered-openapi.yaml
2626
uv.lock
27+
.comfy_environment

comfy/deploy_environment.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import logging
2+
import os
3+
4+
import folder_paths
5+
6+
logger = logging.getLogger(__name__)
7+
8+
_DEFAULT_DEPLOY_ENV = "local_git"
9+
_ENV_FILENAME = ".comfy_environment"
10+
11+
_cached_value: str | None = None
12+
13+
14+
def get_deploy_environment() -> str:
15+
global _cached_value
16+
if _cached_value is not None:
17+
return _cached_value
18+
19+
env_file = os.path.join(folder_paths.base_path, _ENV_FILENAME)
20+
try:
21+
with open(env_file, encoding="utf-8") as f:
22+
first_line = f.readline().strip()
23+
value = "".join(c for c in first_line if 32 <= ord(c) < 127)
24+
if value:
25+
_cached_value = value
26+
return _cached_value
27+
except FileNotFoundError:
28+
pass
29+
except Exception as e:
30+
logger.warning("Failed to read %s: %s", env_file, e)
31+
32+
_cached_value = _DEFAULT_DEPLOY_ENV
33+
return _cached_value

comfy_api_nodes/util/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from comfy_api.latest import IO
2020
from server import PromptServer
2121

22+
from comfy.deploy_environment import get_deploy_environment
23+
2224
from . import request_logger
2325
from ._helpers import (
2426
default_base_url,
@@ -617,6 +619,7 @@ async def _monitor(stop_evt: asyncio.Event, start_ts: float):
617619
payload_headers = {"Accept": "*/*"} if expect_binary else {"Accept": "application/json"}
618620
if not parsed_url.scheme and not parsed_url.netloc: # is URL relative?
619621
payload_headers.update(get_auth_header(cfg.node_cls))
622+
payload_headers["X-Comfy-Env"] = get_deploy_environment()
620623
if cfg.endpoint.headers:
621624
payload_headers.update(cfg.endpoint.headers)
622625

0 commit comments

Comments
 (0)