# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"42",
0
],
"text": "Change the image to let the girl’s hair fall loose around her shoulders, natural and flowing. Don’t change other parts"
},
"_meta": {
"title": "Positive"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"42",
0
],
"text": "low quality, blurry, distorted"
},
"_meta": {
"title": "Negative"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"54",
0
],
"vae": [
"43",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"13": {
"class_type": "LoadImage",
"inputs": {
"image": "hidream_e1_1_input_image.jpg"
},
"_meta": {
"title": "Load Image"
}
},
"41": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "hidream_e1_1_bf16.safetensors",
"weight_dtype": "fp8_e4m3fn_fast"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"42": {
"class_type": "QuadrupleCLIPLoader",
"inputs": {
"clip_name1": "clip_g_hidream.safetensors",
"clip_name2": "clip_l_hidream.safetensors",
"clip_name3": "t5xxl_fp8_e4m3fn_scaled.safetensors",
"clip_name4": "llama_3.1_8b_instruct_fp8_scaled.safetensors"
},
"_meta": {
"title": "Load CLIP (Quadruple)"
}
},
"43": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"45": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"13",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "area"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"46": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"47": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 567500569211369
},
"_meta": {
"title": "RandomNoise"
}
},
"49": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"55",
0
],
"scheduler": "simple",
"steps": 20
},
"_meta": {
"title": "BasicScheduler"
}
},
"52": {
"class_type": "InstructPixToPixConditioning",
"inputs": {
"negative": [
"7",
0
],
"pixels": [
"45",
0
],
"positive": [
"6",
0
],
"vae": [
"43",
0
]
},
"_meta": {
"title": "InstructPixToPixConditioning"
}
},
"53": {
"class_type": "DualCFGGuider",
"inputs": {
"cfg_cond2_negative": 1.5,
"cfg_conds": 3,
"cond1": [
"52",
0
],
"cond2": [
"52",
1
],
"model": [
"55",
0
],
"negative": [
"6",
0
],
"style": "regular"
},
"_meta": {
"title": "Dual CFG Guider"
}
},
"54": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"53",
0
],
"latent_image": [
"52",
2
],
"noise": [
"47",
0
],
"sampler": [
"46",
0
],
"sigmas": [
"49",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"55": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"41",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)