# 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({
"3": {
"class_type": "GrokVideoNode",
"inputs": {
"aspect_ratio": "auto",
"duration": 5,
"image": [
"7",
0
],
"model": "grok-imagine-video-1.5-lite",
"prompt": "High-fashion editorial video, vibrant pop-art studio portrait. A model in an oversized fluffy faux-fur headpiece of turquoise, lavender-purple, and white, with round gold-rimmed blue mirrored sunglasses, glossy pink lips, and bare shoulders against a seamless hot magenta backdrop. She slowly tilts her chin upward and turns her head slightly to the side with confident, elegant poise. A soft wind machine sweeps the long fur, which ripples and flutters in silky, flowing waves, individual strands catching the light. Her lips part gently into a subtle, cool expression. Studio light glides across the mirrored lenses, creating a sleek reflective glint that sweeps from one lens to the other. The camera performs a smooth, slow push-in with a slight upward arc, giving a cinematic slow-motion feel at 60fps. Crisp beauty lighting, saturated candy colors, high contrast, luxurious magazine-cover aesthetic, Vogue-style fashion film, ultra-detailed fur texture, shallow depth of field, polished commercial look, 5 seconds.",
"resolution": "480p",
"seed": 652094900
},
"_meta": {
"title": "Grok Video"
}
},
"6": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/Grok_video_i2v",
"format": "auto",
"format.codec": "auto",
"video": [
"3",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"7": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("7", "image", client.assets.from_url("https://comfy.org/catalog-media/57506c35-676c-426c-971a-739ec72b55bc/a116b177-84ff-47e7-881a-ab67435f80b3"))
# 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("6"):
output.to_file(output.name)