# 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({
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Firered_image_edit_1.1",
"images": [
"167:126",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"143": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"167:115": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"167:116": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"167:117": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"167:115",
0
],
"image1": [
"167:147",
0
],
"prompt": "",
"vae": [
"167:116",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"167:118": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"167:115",
0
],
"image1": [
"167:147",
0
],
"prompt": "Restyle the woman's outfit and the light while keeping her face, pose, hairstyle and the courtyard architecture exactly as they are. Replace the saffron silk jumpsuit with a floor-length midnight-blue velvet column gown with a high mock neck and long fitted sleeves, and swap the brass torque and cuffs for a single strand of pearls at the throat. Turn the late-afternoon sun into blue-hour dusk: the sky becomes a deep cobalt gradient, the concrete colonnade is lit from below by warm amber uplights, and small paper lanterns glow along the stepped terraces. The reflecting pool now mirrors the lanterns and the darkening sky. Keep the camera position, framing and wide-angle perspective unchanged, with the same full-length view from head to toe, her platform sandals now dark velvet heels.",
"vae": [
"167:116",
0
]
},
"_meta": {
"title": "TextEncodeQwenImageEditPlus (Positive)"
}
},
"167:120": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"167:154",
0
],
"sampling": "flow",
"shift": 3.1
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"167:123": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"167:120",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"167:125": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"167:147",
0
],
"vae": [
"167:116",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"167:126": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"167:130",
0
],
"vae": [
"167:116",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"167:128": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "FireRed-Image-Edit-1.1-transformer.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"167:130": {
"class_type": "KSampler",
"inputs": {
"cfg": [
"167:164",
0
],
"denoise": 1,
"latent_image": [
"167:125",
0
],
"model": [
"167:123",
0
],
"negative": [
"167:117",
0
],
"positive": [
"167:118",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 43,
"steps": [
"167:157",
0
]
},
"_meta": {
"title": "KSampler"
}
},
"167:147": {
"class_type": "FluxKontextImageScale",
"inputs": {
"image": [
"143",
0
]
},
"_meta": {
"title": "FluxKontextImageScale"
}
},
"167:151": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "FireRed-Image-Edit-1.0-Lightning-8steps-v1.0.safetensors",
"model": [
"167:128",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"167:153": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": True
},
"_meta": {
"title": "Enable Lightning LoRA?"
}
},
"167:154": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"167:128",
0
],
"on_true": [
"167:151",
0
],
"switch": [
"167:153",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"167:155": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 40
},
"_meta": {
"title": "Steps"
}
},
"167:156": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 8
},
"_meta": {
"title": "LoRA-Steps"
}
},
"167:157": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"167:155",
0
],
"on_true": [
"167:156",
0
],
"switch": [
"167:153",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"167:162": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 4
},
"_meta": {
"title": "CFG"
}
},
"167:163": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 1
},
"_meta": {
"title": "LoRA-CFG"
}
},
"167:164": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"167:162",
0
],
"on_true": [
"167:163",
0
],
"switch": [
"167:153",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
}
})
workflow.set_input("143", "image", client.assets.from_url("https://comfy.org/catalog-media/24de072d-41d6-4a13-805a-a35fba57ea7e/2672c660-d38f-4adf-a67b-00a19272d65e"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("9"):
output.to_file(output.name)