# 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": "ByteDanceSeedNode",
"inputs": {
"model": "Seed 2.0 Pro",
"model.images.image_1": [
"3",
0
],
"model.temperature": 1,
"prompt": "Thoroughly analyze every visual detail of the reference picture, reverse deduce the full original generation prompt.\nClassify content reasonably, finally output strictly in standard JSON format only, no extra text,\nkey: \"positive_prompt\", \"negative_prompt\".",
"seed": 2135571041,
"system_prompt": ""
},
"_meta": {
"title": "ByteDance Seed"
}
},
"2": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"1",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "angle_3.png"
},
"_meta": {
"title": "Load Image"
}
},
"5": {
"class_type": "RegexReplace",
"inputs": {
"case_insensitive": False,
"count": 1,
"dotall": False,
"multiline": False,
"regex_pattern": "^```(?:json)?\\s*\\n?",
"replace": "",
"string": [
"2",
0
]
},
"_meta": {
"title": "Replace Text (Regex)"
}
},
"6": {
"class_type": "RegexReplace",
"inputs": {
"case_insensitive": False,
"count": 1,
"dotall": False,
"multiline": False,
"regex_pattern": "\\n?```\\s*$",
"replace": "",
"string": [
"5",
0
]
},
"_meta": {
"title": "Replace Text (Regex)"
}
},
"7": {
"class_type": "JsonExtractString",
"inputs": {
"json_string": [
"6",
0
],
"key": "negative_prompt"
},
"_meta": {
"title": "Extract Text from JSON"
}
},
"8": {
"class_type": "JsonExtractString",
"inputs": {
"json_string": [
"6",
0
],
"key": "positive_prompt"
},
"_meta": {
"title": "Extract Text from JSON"
}
},
"9": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"7",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"10": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"8",
0
]
},
"_meta": {
"title": "Preview as Text"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)