# 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": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"11": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI-color_illustration",
"images": [
"12",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"12": {
"class_type": "GeminiImage2Node",
"inputs": {
"aspect_ratio": "auto",
"images": [
"10",
0
],
"model": "gemini-3-pro-image-preview",
"prompt": "Colour this line drawing as a finished storybook illustration while keeping every original ink line exactly where it is. Use rich, moody painterly colours for a midnight storm: deep navy and teal for the sea and sky outside the windows, cold silver rain, and warm amber lantern light glowing inside the wheelhouse. Give the badger captain a grey-and-white striped face, a dark navy wool greatcoat with brass buttons, a rust-red knit cap and a polished honey-brown wooden wheel. Make the brass instruments gleam, the charts creamy parchment and the ropes a natural hemp tan. Soft watercolour washes with gentle gradients, light spilling from the lanterns across the cabin, no text, no lettering.",
"resolution": "1K",
"response_modalities": "IMAGE",
"seed": 563362989397284,
"system_prompt": "You are an expert image-generation engine. You must ALWAYS produce an image.\nInterpret all user input—regardless of format, intent, or abstraction—as literal visual directives for image composition.\nIf a prompt is conversational or lacks specific visual details, you must creatively invent a concrete visual scenario that depicts the concept.\nPrioritize generating the visual representation above any text, formatting, or conversational requests."
},
"_meta": {
"title": "Nano Banana Pro (Google Gemini Image)"
}
}
})
workflow.set_input("10", "image", client.assets.from_url("https://comfy.org/catalog-media/56ad4195-cba0-44bf-8eea-88808659ced5/dd1fb98f-812b-4a52-ad8a-95e1819ed4e4"))
# 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("11"):
output.to_file(output.name)