# 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({
"1": {
"class_type": "LoadImage",
"inputs": {
"image": "templates_mjm_image_to_3d.png"
},
"_meta": {
"title": "Load Image"
}
},
"2": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "1:1",
"images": [
"1",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "Create a side shot from this image, do not change the pose and lighting\n\nNo background",
"resolution": "2K",
"response_modalities": "IMAGE",
"seed": 138687889823595,
"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.",
"thinking_level": "HIGH"
},
"_meta": {
"title": "Nano Banana 2"
}
},
"4": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "1:1",
"images": [
"1",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "Create a rear shot from this image, do not change the pose and lighting\n\nNo background",
"resolution": "2K",
"response_modalities": "IMAGE",
"seed": 226226946819998,
"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.",
"thinking_level": "HIGH"
},
"_meta": {
"title": "Nano Banana 2"
}
},
"6": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"23",
0
],
"images.image1": [
"2",
0
],
"images.image2": [
"4",
0
]
},
"_meta": {
"title": "Batch Images"
}
},
"7": {
"class_type": "TripoImageToModelNode",
"inputs": {
"auto_size": True,
"face_limit": -1,
"geometry_quality": "standard",
"image": [
"6",
0
],
"model_seed": 42,
"model_version": "v3.0-20250812",
"orientation": "default",
"pbr": True,
"quad": False,
"smart_low_poly": False,
"style": "person:person2cartoon",
"texture": True,
"texture_alignment": "geometry",
"texture_quality": "detailed",
"texture_seed": 42
},
"_meta": {
"title": "Tripo: Image to Model (Legacy)"
}
},
"23": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "1:1",
"images": [
"1",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "Remove the background",
"resolution": "2K",
"response_modalities": "IMAGE",
"seed": 80526614165305,
"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.",
"thinking_level": "HIGH"
},
"_meta": {
"title": "Nano Banana 2"
}
},
"24": {
"class_type": "Preview3D",
"inputs": {
"model_file": [
"7",
0
]
},
"_meta": {
"title": "Preview 3D & Animation (DEPRECATED)"
}
},
"25": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"23",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"26": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"2",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"27": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"4",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"28": {
"class_type": "SaveGLB",
"inputs": {
"filename_prefix": "3d/tripo_image2model",
"mesh": [
"7",
2
]
},
"_meta": {
"title": "Save 3D Model"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)