# 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({
"5": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"7",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"7": {
"class_type": "TextGenerate",
"inputs": {
"clip": [
"8",
0
],
"max_length": 2048,
"mtp": "auto",
"prompt": "I am a beginner hiker planning my first three-day walk along a rugged coastal path in late spring, staying in village guesthouses each night. Plan the route for me: a sensible daily distance and roughly how long each day takes, where I can refill water, what to pack for weather that can change from sunshine to sea fog and rain within an hour, and one rainy-day alternative for the hardest stage. Keep it practical and friendly, use short headings for each day, and finish with a five-item checklist I can print.",
"sampling_mode": "on",
"sampling_mode.min_p": 0.05,
"sampling_mode.repetition_penalty": 1.05,
"sampling_mode.seed": 0,
"sampling_mode.temperature": 0.7,
"sampling_mode.top_k": 64,
"sampling_mode.top_p": 0.95,
"thinking": False,
"use_default_template": True
},
"_meta": {
"title": "Generate Text"
}
},
"8": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "ltxv"
},
"_meta": {
"title": "Load CLIP"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)