# 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({
"10": {
"class_type": "OpenAIGPTImage1",
"inputs": {
"background": "opaque",
"custom_height": 1024,
"custom_width": 1024,
"image": [
"14",
0
],
"model": "gpt-image-2",
"n": 1,
"prompt": "A cute cat sitting on a boat, holding a glass of champagne, with the vast ocean in the background, in the style of Studio Ghibli",
"quality": "high",
"seed": 1011675199,
"size": "1024x1024"
},
"_meta": {
"title": "OpenAI GPT Image 2"
}
},
"14": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"15": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"10",
0
]
},
"_meta": {
"title": "Save Image"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("14", "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)