# 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({
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "woman_with_flower_swim_shot.png"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "CreateBoundingBoxes",
"inputs": {
"background": [
"2",
0
],
"editor_state": {
"__value__": []
},
"height": 1152,
"last_incoming": {
"__value__": [
{
"height": 340,
"metadata": {
"desc": "Turn the flowers into goldfish swimming in the water",
"palette": [],
"text": "",
"type": "obj"
},
"width": 588,
"x": 192,
"y": 704
}
]
},
"width": 896
},
"_meta": {
"title": "Create Bounding Boxes"
}
},
"6": {
"class_type": "SaveImageAdvanced",
"inputs": {
"filename_prefix": "api_bfl_flux3_1_image_bboxes",
"format": "png",
"format.bit_depth": "8-bit",
"format.channels": "auto",
"format.input_color_space": "sRGB",
"images": [
"10",
0
]
},
"_meta": {
"title": "Save Image (Advanced)"
}
},
"7": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"2",
0
],
"image_b": [
"6",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"9": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"11",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"10": {
"class_type": "Flux31ImageNode",
"inputs": {
"bounding_boxes": [
"3",
2
],
"images.image_1": [
"2",
0
],
"images.image_2": "quality",
"mask": "match image 1",
"prompt": [
"9",
0
]
},
"_meta": {
"title": "Flux31ImageNode"
}
},
"11": {
"class_type": "Flux3LayoutPrompt",
"inputs": {
"element": [
"3",
2
],
"prompt": "In image 1, change only what the boxed elements describe and keep everything else exactly as it is."
},
"_meta": {
"title": "FLUX 3 Image Layout Prompt"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)