# 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({
"2": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Qwen-image-3.0-pro",
"images": [
"15",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"14": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"15": {
"class_type": "QwenImageEditApi",
"inputs": {
"model": "qwen-image-3.0-pro",
"model.images.image_1": [
"14",
0
],
"model.negative_prompt": "",
"model.prompt": "The reference image is an apocalyptic wasteland-style armed traveling merchant character. Based on this character, generate a 1:1 square character sheet in game character design document style.\nThe layout is divided into four blocks on a light gray background with thin line-frame sections:\n1. Top-left: full-body standing illustration. Keep ALL features from the reference: a dark wide-brimmed hat or large hood, dark reddish-brown skin, dark tactical underlayer, a bright camel-colored long coat, dark trousers and boots, holding a long rifle, a weapon strapped to the back, and packs of goods piled at the feet. Figure centered, single side lighting.\n2. Top-right: close-up of the head. Show the face under the hat brim: dark reddish-brown skin, facial contours, goggles or mask details, the hat's material texture.\n3. Bottom-left: costume and accessory breakdown. Show the camel coat's cut, the dark underlayer, belt and gloves, boots, with key parts annotated.\n4. Bottom-right: character info card with text: name \"Wandering Merchant\", occupation \"Wasteland Trader\", tags \"Armed Caravan / Lone Traveler / Trade and Survival\".\nOverall: realistic 3D concept art style, low-saturation palette (cool gray-green, warm camel, dark brown), clear accurate text, information-dense but not crowded, like a game art character sheet.\nMust preserve the character identity from the reference: the headwear, skin tone, coat colors, weapon and goods must not change.",
"n": 1,
"prompt_extend": True,
"seed": 1082970520,
"size": "match input",
"watermark": False
},
"_meta": {
"title": "Qwen Image 3 Edit"
}
}
})
workflow.set_input("14", "image", client.assets.from_url("https://comfy.org/catalog-media/08dea9e1-71da-4aab-9b8f-af40125cd587/cbee9ea6-ab05-4139-868f-291e7e14dd21"))
# 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("2"):
output.to_file(output.name)