# 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": "carbon_fibre_controller.png"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "BuildJsonPromptIdeogram",
"inputs": {
"aesthetics": "",
"background": "",
"color_palette": {
"__value__": []
},
"element": [
"4",
2
],
"high_level_description": "Edit @Image1: change ONLY the two side grip panels of the controller. Replace their carbon-fibre weave\nwith anodised aluminium: a fine bead-blasted, satin metallic surface in deep graphite grey, uniform and\nmatte, with a very subtle micro-texture, softly diffused anisotropic highlight running along the length\nof each grip, and crisp machined bevels where the panels meet the body. The metal must read as one solid\nmachined part, not a wrap or a sticker: no carbon weave, no fabric, no brushed lines crossing the shape.\nKeep the lighting exactly as shot: the existing cool rim light from the upper right produces one soft\nelongated highlight ridge per grip, nothing new is lit. The glossy black centre body, the joysticks,\nbuttons, D-pad, centre touchpad, seams, screws, every reflection and the entire background stay\npixel-identical and untouched. No text, no logo, no scratches, no fingerprints.",
"lighting": "",
"medium": "",
"style": "none"
},
"_meta": {
"title": "Build JSON Prompt (Ideogram)"
}
},
"4": {
"class_type": "CreateBoundingBoxes",
"inputs": {
"background": [
"2",
0
],
"editor_state": {
"__value__": []
},
"height": 2720,
"last_incoming": {
"__value__": []
},
"width": 1536
},
"_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": "api_ideogram_v4_6_precise_image_edit",
"format": "png",
"format.bit_depth": "8-bit",
"format.channels": "auto",
"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.6",
"model.context_window": "auto",
"model.images.image_1": [
"2",
0
],
"model.prompt": [
"5",
0
],
"model.quality": "medium",
"model.seed": 1496257313
},
"_meta": {
"title": "Ideogram Precise Edit"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)