# 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({
"83": {
"class_type": "FluxKontextProImageNode",
"inputs": {
"aspect_ratio": "1:1",
"guidance": 3,
"input_image": [
"91",
0
],
"prompt": "Change the image to pop art style poster",
"prompt_upsampling": False,
"seed": 0,
"steps": 50
},
"_meta": {
"title": "Flux.1 Kontext [pro] Image"
}
},
"84": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"85": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"83",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"91": {
"class_type": "ImageStitch",
"inputs": {
"direction": "right",
"image1": [
"84",
0
],
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 8
},
"_meta": {
"title": "Stitch Images"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("84", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)