# 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({
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"5",
1
]
},
"_meta": {
"title": "Preview as Text"
}
},
"5": {
"class_type": "GeminiImageNode",
"inputs": {
"aspect_ratio": "16:9",
"images": [
"2",
0
],
"model": "gemini-2.5-flash-image",
"prompt": "Keep the runner, the pose, the gravel plain, the fog and the grainy film look exactly as they are. Fill the huge empty sky above with dozens of enormous hand-made paper kites drifting on the wind: long tails of faded red, ochre and pale blue rice paper, bamboo frames showing through the thin paper, strings trailing down toward the horizon. Some kites are close and towering over the runner, others shrink into the fog in the distance, giving the scene depth. Let the soft dawn light glow through the paper so each kite looks backlit and slightly translucent, with small tears and creases in the paper. The mood shifts from bleak to quietly magical, but the photo still looks like a real, slightly faded film photograph from the seventies.",
"response_modalities": "IMAGE+TEXT",
"seed": 851454814947321,
"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 (Google Gemini Image)"
}
},
"30": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"5",
0
]
},
"_meta": {
"title": "Save Image"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/cd09fb73-a5ed-436c-a375-5e6fde4b12f9/9978e36a-45c2-4558-8836-806dba33608d"))
# 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("30"):
output.to_file(output.name)