# 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({
"12": {
"class_type": "WanTextToImageApi",
"inputs": {
"height": 1024,
"model": "wan2.5-t2i-preview",
"negative_prompt": "",
"prompt": "Backlighting, medium shot, sunset, soft light, silhouette, central composition, circular camera movement. The camera follows the character from behind to the front, showing a rugged cowboy gripping his holster tightly, his eyes alert as he patrols the desolate Western ghost town. The cowboy wears a worn brown leather jacket, with a bullet belt around his waist and the brim of his hat pulled low. His outline is sketched into a soft silhouette by the setting sun. Behind him are dilapidated wooden buildings with long-broken windows, glass shards scattered on the ground, and dust swirling in the wind. The camera slowly circles from his back to his front, with light pouring from behind, creating a strong dramatic contrast. The scene presents warm tones, enhancing the desolate atmosphere.",
"prompt_extend": True,
"seed": 6926862,
"watermark": False,
"width": 1024
},
"_meta": {
"title": "Wan Text to Image"
}
},
"13": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Wan2.5-t2i-preview",
"images": [
"12",
0
]
},
"_meta": {
"title": "Save Image"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)