From 81651606a6e7ec81d3551f68f31cb2a727384264 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Wed, 18 Mar 2026 19:23:59 -0700 Subject: [PATCH] feat: add execution environment API for managed deployments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds api.environment.get() to the public ComfyAPI — returns "local" (default), "cloud", or "remote" based on the COMFY_EXECUTION_ENVIRONMENT env var. Custom nodes use this to adapt behavior for managed deployments (e.g. skip model downloads when models are pre-provisioned). --- comfy_api/latest/__init__.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/comfy_api/latest/__init__.py b/comfy_api/latest/__init__.py index 04973fea0..7823c5baf 100644 --- a/comfy_api/latest/__init__.py +++ b/comfy_api/latest/__init__.py @@ -15,6 +15,7 @@ from comfy_execution.progress import get_progress_state, PreviewImageTuple from PIL import Image from comfy.cli_args import args import numpy as np +import os class ComfyAPI_latest(ComfyAPIBase): @@ -25,6 +26,7 @@ class ComfyAPI_latest(ComfyAPIBase): super().__init__() self.node_replacement = self.NodeReplacement() self.execution = self.Execution() + self.environment = self.Environment() self.caching = self.Caching() class NodeReplacement(ProxiedSingleton): @@ -85,6 +87,27 @@ class ComfyAPI_latest(ComfyAPIBase): image=to_display, ) + class Environment(ProxiedSingleton): + """ + Query the current execution environment. + + Managed deployments set the ``COMFY_EXECUTION_ENVIRONMENT`` env var + so custom nodes can adapt their behaviour at runtime. + + Example:: + + from comfy_api.latest import api + + env = api.environment.get() # "local" | "cloud" | "remote" + """ + + _VALID = {"local", "cloud", "remote"} + + async def get(self) -> str: + """Return the execution environment: ``"local"``, ``"cloud"``, or ``"remote"``.""" + value = os.environ.get("COMFY_EXECUTION_ENVIRONMENT", "local").lower().strip() + return value if value in self._VALID else "local" + class Caching(ProxiedSingleton): """ External cache provider API for sharing cached node outputs