# 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": "UPLOADED_style_image_FILENAME"
},
"_meta": {
"title": "Style Reference"
}
},
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_object_image_FILENAME"
},
"_meta": {
"title": "Sprite Reference"
}
},
"3": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "texture_alpha",
"images": [
"4",
0
]
},
"_meta": {
"title": "Save texture with alpha"
}
},
"4": {
"class_type": "RecraftRemoveBackgroundNode",
"inputs": {
"image": [
"8",
0
]
},
"_meta": {
"title": "Recraft Remove Background"
}
},
"5": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "texture",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save texture"
}
},
"7": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": {
"__value__": [
"",
""
]
},
"image_a": [
"2",
0
],
"image_b": [
"8",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"8": {
"class_type": "GeminiImage2Node",
"inputs": {
"aspect_ratio": "1:1",
"images": [
"16",
0
],
"model": "gemini-3-pro-image-preview",
"prompt": [
"21",
0
],
"resolution": "1K",
"response_modalities": "IMAGE",
"seed": 605332021762553,
"system_prompt": "You are an expert image-generation engine. You must ALWAYS produce an image.\nInterpret all user input—regardless of format, intent, or abstraction—as literal visual directives for image composition.\nIf a prompt is conversational or lacks specific visual details, you must creatively invent a concrete visual scenario that depicts the concept.\nPrioritize generating the visual representation above any text, formatting, or conversational requests."
},
"_meta": {
"title": "Nano Banana Pro (Google Gemini Image)"
}
},
"16": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"2",
0
],
"images.image1": [
"1",
0
]
},
"_meta": {
"title": "Batch Images"
}
},
"17": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": [
"19",
0
],
"string_b": [
"22",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"19": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "strictly preserve the composition and outline of image 1. Reskin image 1 as "
},
"_meta": {
"title": "Text (Multiline)"
}
},
"20": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": " and restyle into the style of image 2. Black background"
},
"_meta": {
"title": "Text (Multiline)"
}
},
"21": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": [
"17",
0
],
"string_b": [
"20",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"22": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "art deco brass siphon pump"
},
"_meta": {
"title": "Object Prompt"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/28407515-9896-487f-940f-aefd88e11731/775ff4e9-4158-4142-b3d6-b21946b30c52"))
workflow.set_input("1", "image", client.assets.from_url("https://comfy.org/catalog-media/884c68fb-ed2d-4c97-9097-70a055e180d4/e7f07b36-50b9-4898-ad55-e5d020356d1e"))
# 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("3"):
output.to_file(output.name)
for output in job.get_outputs("5"):
output.to_file(output.name)