# 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": "GrokImageEditNodeV2",
"inputs": {
"model": "grok-imagine-image-2.0",
"model.aspect_ratio": "16:9",
"model.images.image_1": [
"11",
0
],
"model.images.image_2": [
"13",
0
],
"model.number_of_images": 1,
"model.quality": "medium",
"model.resolution": "1K",
"prompt": "Create a warm commercial cookware photograph. Use the first reference image as the character reference, keeping the woman's face, sculpted finger-wave hair, charcoal jacket and teal collared shirt. Use the second reference image as the product reference, keeping the round terracotta-orange enamel pot with its brass knob exactly as shown. She stands at a rustic farmhouse kitchen counter, lifting the lid of the pot with one hand as a curl of steam rises from a bubbling vegetable stew inside, smiling as she leans in to smell it. Morning sunlight streams through a window behind her, catching the steam and the glossy enamel. Fresh herbs, a wooden spoon and a loaf of bread sit on the counter. Shallow depth of field keeps the pot, her hand and the steam in sharp focus, with soft cream and copper tones throughout.",
"seed": 733312228
},
"_meta": {
"title": "Grok Image Edit"
}
},
"11": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_1_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"12": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Grok_imagine_image_2.0",
"images": [
"10",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"13": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("11", "image", client.assets.from_url("https://comfy.org/catalog-media/7d7da26a-1dbc-4b73-bd08-dfc1700bd62b/8efe9eba-8314-43cd-b3a7-0ababc432cd9"))
workflow.set_input("13", "image", client.assets.from_url("https://comfy.org/catalog-media/f203bf96-6955-46cb-b028-2d59a2a473a0/8de06ce6-0bab-4c34-9c67-4aca933ca0b8"))
# 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("12"):
output.to_file(output.name)