# 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({
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "LongCat-Image",
"images": [
"13:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"14": {
"class_type": "ResolutionSelector",
"inputs": {
"aspect_ratio": "1:1 (Square)",
"megapixels": 1,
"multiple": 8
},
"_meta": {
"title": "Resolution Selector"
}
},
"13:1": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "longcat_image_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"13:10": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"13:1",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"13:11": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"13:4",
0
],
"guidance": 4
},
"_meta": {
"title": "FluxGuidance"
}
},
"13:12": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"13:5",
0
],
"guidance": 4
},
"_meta": {
"title": "FluxGuidance"
}
},
"13:2": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "longcat_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"13:3": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"13:4": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"13:2",
0
],
"text": "High-fashion portrait of a man with a shaved head and stubble, head tilted back and gazing upward. His skin and thick-knitted dark green turtleneck sweater are bathed in a monochromatic teal-green light, creating a uniform, matte finish. He wears round, thin-framed sunglasses with reflective amber-orange lenses that catch the light. The background is a solid, vibrant burnt orange, creating a bold, high-contrast color palette. The lighting is hard and directional, casting sharp shadows on his face. Hyper-detailed, photorealistic, sharp focus on facial features and fabric texture, editorial photography, 8K."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"13:5": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"13:2",
0
],
"text": "blurry, low resolution, oversaturated, harsh lighting, messy composition, distorted face, extra fingers, bad anatomy, cheap jewelry, plastic texture, cartoon, illustration, anime, watermark, text, logo"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"13:6": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": [
"14",
1
],
"width": [
"14",
0
]
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"13:7": {
"class_type": "KSampler",
"inputs": {
"cfg": 4,
"denoise": 1,
"latent_image": [
"13:6",
0
],
"model": [
"13:10",
0
],
"negative": [
"13:12",
0
],
"positive": [
"13:11",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 284089112874294,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"13:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"13:7",
0
],
"vae": [
"13:3",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)