# 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({
"1": {
"class_type": "Krea3ImageNode",
"inputs": {
"model": "Krea 3",
"model.aspect_ratio": "16:9",
"model.images.image_0": [
"8",
0
],
"model.precise_edit": True,
"model.prompt": "Recolour the muscle car that fills the centre of the frame from its current green to a deep matte burnt orange, keeping every panel line, chrome bumper, badge and window exactly where it is. Swap the plain steel wheels for polished five-spoke alloys with a warm bronze centre. Leave the derelict filling station, the cracked concrete, the fuel pumps, the mesa horizon and the dust plume behind the rear wheels untouched, and keep the low golden-hour sun raking from the left so the new paint reads matte where it faces the light and falls into deep shadow under the arches.",
"model.resolution": "1K",
"model.seed": 2087889669,
"model.thinking_mode": "fast"
},
"_meta": {
"title": "Krea 3 Image"
}
},
"7": {
"class_type": "SaveImageAdvanced",
"inputs": {
"filename_prefix": "api_krea3_image_edit",
"format": "png",
"format.bit_depth": "8-bit",
"format.input_color_space": "sRGB",
"images": [
"1",
0
]
},
"_meta": {
"title": "Save Image (Advanced)"
}
},
"8": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image1_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("8", "image", client.assets.from_url("https://comfy.org/catalog-media/3c2a7ed8-1303-4494-a85b-817528262e06/7986ca2f-57df-4a78-acaa-6237648cbe58"))
# 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)