# 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({
"136": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"192:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"190": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"192:124": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"192:42",
0
],
"vae": [
"192:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"192:135": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"192:6",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"192:146": {
"class_type": "ImageStitch",
"inputs": {
"direction": "right",
"image1": [
"190",
0
],
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 0
},
"_meta": {
"title": "Stitch Images"
}
},
"192:177": {
"class_type": "ReferenceLatent",
"inputs": {
"conditioning": [
"192:6",
0
],
"latent": [
"192:124",
0
]
},
"_meta": {
"title": "Set Reference Latent"
}
},
"192:31": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"192:124",
0
],
"model": [
"192:37",
0
],
"negative": [
"192:135",
0
],
"positive": [
"192:35",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 784381637916598,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"192:35": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"192:177",
0
],
"guidance": 2.5
},
"_meta": {
"title": "FluxGuidance"
}
},
"192:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-dev-kontext_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"192:38": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"192:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"192:42": {
"class_type": "FluxKontextImageScale",
"inputs": {
"image": [
"192:146",
0
]
},
"_meta": {
"title": "FluxKontextImageScale"
}
},
"192:6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"192:38",
0
],
"text": "Change the season and the time of day while keeping the woodcarver, his pose, the workbench and the whole layout of the workshop exactly as they are. It is now a snowy winter evening: deep blue dusk outside the tall windows, snow piled on the window ledges and falling softly beyond the glass. Inside, warm amber light from a few hanging pendant lamps and a glowing cast-iron stove in the corner replaces the cold daylight, casting soft orange highlights on the wood shavings, the timber racks and the carver's hands and face. Keep the same camera angle, the same documentary photographic style, the same textures of wood, denim and steel, and do not add any people, lettering or signs."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"192:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"192:31",
0
],
"vae": [
"192:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
workflow.set_input("190", "image", client.assets.from_url("https://comfy.org/catalog-media/86baffb0-590c-4284-a5e1-70bfcee63197/48e4a7e1-d791-4d4a-a8f4-3c4bf47a393f"))
# 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("136"):
output.to_file(output.name)