# 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": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"21": {
"class_type": "SaveGLB",
"inputs": {
"filename_prefix": "3d/ComfyUI",
"mesh": [
"67:54",
0
]
},
"_meta": {
"title": "Save 3D Model"
}
},
"46": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"67:63",
0
]
},
"_meta": {
"title": "Preview Image (normal_opengl)"
}
},
"47": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"67:64",
0
]
},
"_meta": {
"title": "Preview Image (normal_directx)"
}
},
"67:54": {
"class_type": "MoGePointMapToMesh",
"inputs": {
"batch_index": 0,
"decimation": 1,
"discontinuity_threshold": 0.04,
"moge_geometry": [
"67:55",
0
],
"texture": True
},
"_meta": {
"title": "Convert MoGe Point Map to Mesh"
}
},
"67:55": {
"class_type": "MoGeInference",
"inputs": {
"apply_mask": True,
"batch_size": 4,
"force_projection": True,
"fov_x_degrees": 0,
"image": [
"67:66",
0
],
"moge_model": [
"67:58",
0
],
"refine_steps": 3,
"resolution_level": 9
},
"_meta": {
"title": "Run MoGe Inference"
}
},
"67:58": {
"class_type": "LoadMoGeModel",
"inputs": {
"model_name": "moge_2_vitl_normal_fp16.safetensors"
},
"_meta": {
"title": "Load MoGe Model"
}
},
"67:59": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "a > 2048",
"values.a": [
"67:60",
0
]
},
"_meta": {
"title": "Math Expression"
}
},
"67:60": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"9",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"67:61": {
"class_type": "ImageScaleToMaxDimension",
"inputs": {
"image": [
"9",
0
],
"largest_size": 2048,
"upscale_method": "lanczos"
},
"_meta": {
"title": "Scale Image to Max Dimension"
}
},
"67:62": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"9",
0
],
"on_true": [
"67:61",
0
],
"switch": [
"67:59",
2
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"67:63": {
"class_type": "MoGeRender",
"inputs": {
"moge_geometry": [
"67:55",
0
],
"output": "normal_opengl"
},
"_meta": {
"title": "Render MoGe Geometry"
}
},
"67:64": {
"class_type": "MoGeRender",
"inputs": {
"moge_geometry": [
"67:55",
0
],
"output": "normal_directx"
},
"_meta": {
"title": "Render MoGe Geometry"
}
},
"67:66": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"9",
0
],
"on_true": [
"67:62",
0
],
"switch": True
},
"_meta": {
"title": "If/Else Switch"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("9", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)