# 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": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "BuildJsonPromptIdeogram",
"inputs": {
"aesthetics": "",
"background": "",
"color_palette": {
"__value__": []
},
"element": [
"4",
2
],
"high_level_description": "Turn the labeled area into the described change, keep everything else identical.",
"lighting": "",
"medium": "",
"style": "none"
},
"_meta": {
"title": "Build JSON Prompt (Ideogram)"
}
},
"4": {
"class_type": "CreateBoundingBoxes",
"inputs": {
"background": [
"2",
0
],
"editor_state": {
"__value__": []
},
"height": 1152,
"last_incoming": {
"__value__": [
{
"height": 128,
"metadata": {
"desc": "Change the earring to pearl earring",
"palette": [],
"text": "",
"type": "obj"
},
"width": 128,
"x": 448,
"y": 384
}
]
},
"width": 896
},
"_meta": {
"title": "Create Bounding Boxes"
}
},
"5": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"3",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"7": {
"class_type": "SaveImageAdvanced",
"inputs": {
"filename_prefix": "ideogram4.5_image_edit",
"format": "png",
"format.bit_depth": "8-bit",
"format.input_color_space": "sRGB",
"images": [
"20",
0
]
},
"_meta": {
"title": "Save Image (Advanced)"
}
},
"8": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"2",
0
],
"image_b": [
"7",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"20": {
"class_type": "IdeogramPreciseEditApi",
"inputs": {
"model": "ideogram-4.5",
"model.context_window": "none",
"model.images.image_1": [
"2",
0
],
"model.prompt": [
"5",
0
],
"model.quality": "medium",
"model.seed": 564797084
},
"_meta": {
"title": "Ideogram 4.5 Precise Edit"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/bfcefe1b-cb03-439a-8648-443b00b1cdbc/f9132a51-b3f6-4f74-8609-b956035000ce"))
# 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("7"):
output.to_file(output.name)