# 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({
"17": {
"class_type": "LoadImage",
"inputs": {
"image": "image_flux.1_fill_dev_OneReward_input_image.png"
},
"_meta": {
"title": "Load Image"
}
},
"62": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"110:65",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"105": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"108:8",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"121": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"17",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"108:100": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "removal_timestep_alpha-2-1740.safetensors",
"model": [
"108:31",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"108:23": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"108:34",
0
],
"text": "Remove the girl's hat\n"
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"108:26": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"108:23",
0
],
"guidance": 30
},
"_meta": {
"title": "FluxGuidance"
}
},
"108:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"108:38",
2
],
"model": [
"108:39",
0
],
"negative": [
"108:38",
1
],
"positive": [
"108:38",
0
],
"sampler_name": "euler",
"scheduler": "normal",
"seed": 1100974460616450,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"108:31": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux.1-fill-dev-OneReward-transformer_fp8.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"108:32": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"108:34": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp16.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"108:38": {
"class_type": "InpaintModelConditioning",
"inputs": {
"mask": [
"17",
1
],
"negative": [
"108:46",
0
],
"noise_mask": True,
"pixels": [
"17",
0
],
"positive": [
"108:26",
0
],
"vae": [
"108:32",
0
]
},
"_meta": {
"title": "InpaintModelConditioning"
}
},
"108:39": {
"class_type": "DifferentialDiffusion",
"inputs": {
"model": [
"108:100",
0
],
"strength": 1
},
"_meta": {
"title": "Differential Diffusion"
}
},
"108:46": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"108:23",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"108:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"108:3",
0
],
"vae": [
"108:32",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"110:57": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp16.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"110:58": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"110:73",
0
],
"model": [
"110:63",
0
],
"negative": [
"110:71",
1
],
"positive": [
"110:71",
0
],
"sampler_name": "euler",
"scheduler": "normal",
"seed": 325184035774450,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"110:59": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"110:60": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"110:74",
0
],
"guidance": 30
},
"_meta": {
"title": "FluxGuidance"
}
},
"110:61": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"110:74",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"110:63": {
"class_type": "DifferentialDiffusion",
"inputs": {
"model": [
"110:64",
0
],
"strength": 1
},
"_meta": {
"title": "Differential Diffusion"
}
},
"110:64": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux.1-fill-dev-OneReward-transformer_fp8.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"110:65": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"110:58",
0
],
"vae": [
"110:59",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"110:71": {
"class_type": "InpaintModelConditioning",
"inputs": {
"mask": [
"110:75",
1
],
"negative": [
"110:61",
0
],
"noise_mask": False,
"pixels": [
"110:75",
0
],
"positive": [
"110:60",
0
],
"vae": [
"110:59",
0
]
},
"_meta": {
"title": "InpaintModelConditioning"
}
},
"110:73": {
"class_type": "SetLatentNoiseMask",
"inputs": {
"mask": [
"110:75",
1
],
"samples": [
"110:71",
2
]
},
"_meta": {
"title": "Set Latent Noise Mask"
}
},
"110:74": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"110:57",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"110:75": {
"class_type": "ImagePadForOutpaint",
"inputs": {
"bottom": 104,
"feathering": 40,
"image": [
"17",
0
],
"left": 40,
"right": 104,
"top": 0
},
"_meta": {
"title": "Pad Image for Outpainting"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)