# 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({
"11": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"32": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "api_bytedance_seedream_5_5_image_edit",
"images": [
"40",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"38": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"11",
0
],
"image_b": [
"32",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"40": {
"class_type": "ByteDanceSeedreamNodeV3",
"inputs": {
"model": "seedream 5.5",
"model.background": "auto",
"model.height": [
"41",
1
],
"model.images.image_1": [
"11",
0
],
"model.seed": 42,
"model.size_preset": "Custom",
"model.watermark": False,
"model.width": [
"41",
0
],
"prompt": "Change the chocolate to a lilac macaron, hair to a chin-length bob, earrings to pearl studs, top to lavender ruffle blouse, background to soft lilac. Keep the same face, smile, pose, hand covering the left eye, and framing.\n\nKeep same face, smile, pose, and framing. No text."
},
"_meta": {
"title": "ByteDance Seedream 4.5, 5.0 & 5.5"
}
},
"41": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"11",
0
]
},
"_meta": {
"title": "Get Image Size"
}
}
})
workflow.set_input("11", "image", client.assets.from_url("https://comfy.org/catalog-media/b5c7974e-1674-423b-bd22-f1462d964890/a530f628-c1e8-4fdc-9d4d-95acfb2e50d9"))
# 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("32"):
output.to_file(output.name)