# 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": "LoadImage",
"inputs": {
"image": "input_style_1.png"
},
"_meta": {
"title": "Load Style Image 1"
}
},
"6": {
"class_type": "RecraftCreateStyleNode",
"inputs": {
"images.image0": [
"1",
0
],
"images.image1": [
"23",
0
],
"images.image2": [
"24",
0
],
"images.image3": [
"25",
0
],
"images.image4": [
"26",
0
],
"style": "realistic_image"
},
"_meta": {
"title": "Recraft Create Style"
}
},
"7": {
"class_type": "RecraftStyleV3InfiniteStyleLibrary",
"inputs": {
"style_id": [
"6",
0
]
},
"_meta": {
"title": "Recraft - Infinite Style Library"
}
},
"8": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"6",
0
]
},
"_meta": {
"title": "Preview Recraft Style ID"
}
},
"23": {
"class_type": "LoadImage",
"inputs": {
"image": "input_style_2.png"
},
"_meta": {
"title": "Load Style Image 2"
}
},
"24": {
"class_type": "LoadImage",
"inputs": {
"image": "input_style_3.png"
},
"_meta": {
"title": "Load Style Image 3"
}
},
"25": {
"class_type": "LoadImage",
"inputs": {
"image": "input_style_4.png"
},
"_meta": {
"title": "Load Style Image 4"
}
},
"26": {
"class_type": "LoadImage",
"inputs": {
"image": "input_style_5.png"
},
"_meta": {
"title": "Load Style Image 5"
}
},
"37": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI-t2i_style_transfer",
"images": [
"45",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"41": {
"class_type": "RecraftStyleV3InfiniteStyleLibrary",
"inputs": {
"style_id": "COPY PASTE STYLE ID HERE AND CONNECT"
},
"_meta": {
"title": "Recraft - Infinite Style Library (Manual)"
}
},
"45": {
"class_type": "RecraftTextToImageNode",
"inputs": {
"n": 1,
"negative_prompt": "",
"prompt": "extreme wide shot of an grand colosseum, dynamic angled composition",
"recraft_style": [
"7",
0
],
"seed": 0,
"size": "1024x1024"
},
"_meta": {
"title": "Recraft V3 Text to Image"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)