# 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": "ClaudeNode",
"inputs": {
"images.image_1": [
"12",
0
],
"model": "Fable 5.1",
"model.max_tokens": 32768,
"model.reasoning_effort": "high",
"prompt": [
"14",
0
],
"seed": 1299859456,
"system_prompt": ""
},
"_meta": {
"title": "Anthropic Claude"
}
},
"12": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"13": {
"class_type": "SaveText",
"inputs": {
"filename_prefix": "Claude/Fable_5",
"format": "txt",
"text": [
"16:8",
0
]
},
"_meta": {
"title": "Save Text"
}
},
"14": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Analyze all visual features of the image, generate standard AI art positive prompt.\nExtract subject, character pose, composition, camera angle, lighting, color palette, texture, art style, rendering type, background and details.\nArrange content in order: subject, composition & camera, lighting & color, texture & style, image quality. Separate words with commas.\nOnly output positive prompt, no extra explanations, no negative prompts."
},
"_meta": {
"title": "Text (User Prompt)"
}
},
"15": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"1",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"16:6": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "USER PROMPT:\n\n",
"string_b": [
"14",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"16:7": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "\n\nOUTPUT:\n\n",
"string_b": [
"15",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"16:8": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": [
"16:6",
0
],
"string_b": [
"16:7",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
}
})
workflow.set_input("12", "image", client.assets.from_url("https://comfy.org/catalog-media/7473ff64-1207-448d-b966-d31f7eaccb67/0b4064d2-fd52-4d1e-902c-ae92644176d4"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)