# 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": "NewBie-Image-Exp0.1",
"images": [
"41:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"43": {
"class_type": "StringReplace",
"inputs": {
"find": "{user_prompt}",
"replace": [
"48",
0
],
"string": [
"47",
0
]
},
"_meta": {
"title": "Replace Text"
}
},
"44": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Painterly anime illustration of a young female herbalist standing full body amidst a sprawling ancient forest sanctuary. She has long, wind-tousled lavender hair adorned with a silver hairpin and large, curious amber eyes. She wears an intricately layered traveling robe featuring embroidered wisteria patterns, a pleated indigo skirt, a brass-buckled leather utility corset holding glass potion vials, and laced walking boots. Pausing on an arched mossy stone bridge, she turns her torso toward the viewer with a gentle, serene smile, delicately holding a woven flower basket. The vast landscape spreads out behind her, revealing ancient ivy-covered stone towers, a tranquil river winding into a misty valley, and scattered wild blossoms. Soft twilight radiates through the forest canopy, casting golden hour highlights and glowing floating spores across the scene. Rich, clean line art and warm watercolor-inspired shading."
},
"_meta": {
"title": "Caption"
}
},
"46": {
"class_type": "StringReplace",
"inputs": {
"find": "{caption}",
"replace": [
"44",
0
],
"string": [
"43",
0
]
},
"_meta": {
"title": "Replace Text"
}
},
"47": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "You are an assistant designed to generate high-quality anime images with the highest degree of image-text alignment based on xml format textual prompts. <Prompt Start>\n{\n\"character_1\": {\n\"bbox\": [\n0,\n0,\n1000,\n1000\n],\n\"name\": \"$character_1$\"\n},\n\"image\": {\n\"tags\": \"\n{user_prompt}\n\",\n\"caption\": \"{caption}\"\n}\n}"
},
"_meta": {
"title": "Prompt Template"
}
},
"48": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "<character_1>\n<n>$character_1$</n>\n<gender>1girl</gender>\n<appearance>lavender hair, long hair, wind-blown hair, silver hairpin, amber eyes, large eyes, fair skin</appearance>\n<clothing>layered traveling robe, wisteria embroidery, pleated indigo skirt, leather corset, brass buckles, potion vials, laced boots</clothing>\n<body_type>slender</body_type>\n<expression>gentle smile, serene, looking at viewer</expression>\n<action>standing, turning toward viewer, holding basket, flower basket</action>\n<interaction>none</interaction>\n<position>full body, center, mid-ground</position>\n</character_1>\n\n<general_tags>\n<count>1girl</count>\n<style>anime style, painterly, watercolor shading, clean line art, illustration</style>\n<background>ancient forest, ivy-covered stone towers, winding river, misty valley</background>\n<environment>arched mossy stone bridge, wild flowers, floating spores</environment>\n<perspective>wide shot, eye level</perspective>\n<atmosphere>peaceful, magical, whimsical</atmosphere>\n<lighting>twilight, golden hour, soft light, light rays through canopy</lighting>\n<quality>masterpiece, best quality, newest, highres, absurdres, detailed</quality>\n<objects>woven basket, glass vials, hairpin</objects>\n</general_tags>"
},
"_meta": {
"title": "User Prompt"
}
},
"41:26": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"41:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 5.5,
"denoise": 1,
"latent_image": [
"41:31",
0
],
"model": [
"41:32",
0
],
"negative": [
"41:49",
0
],
"positive": [
"41:43",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 27582042565232,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"41:30": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "NewBie-Image-Exp0.1-bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"41:31": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 864,
"width": 1536
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"41:32": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"41:30",
0
],
"sampling": "flow",
"shift": 6
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"41:34": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "gemma_3_4b_it_bf16.safetensors",
"clip_name2": "jina_clip_v2_bf16.safetensors",
"device": "default",
"type": "newbie"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"41:43": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"41:34",
0
],
"text": [
"46",
0
]
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"41:49": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"41:34",
0
],
"text": "You are an assistant designed to generate low-quality images based on textual prompts. <Prompt Start>"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"41:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"41:3",
0
],
"vae": [
"41:26",
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)
for output in job.get_outputs("9"):
output.to_file(output.name)