# 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": "LoadImage",
"inputs": {
"image": "example.png"
},
"_meta": {
"title": "Load Image"
}
},
"19": {
"class_type": "SaveText",
"inputs": {
"filename_prefix": "Text/GPT",
"format": "txt",
"text": [
"20",
0
]
},
"_meta": {
"title": "Save Text"
}
},
"20": {
"class_type": "OpenAIChatNodeV2",
"inputs": {
"model": "gpt-6.2-sol",
"model.images.image_1": [
"5",
0
],
"model.max_output_tokens": 32768,
"model.prompt": "Describe this image",
"model.reasoning_effort": "medium",
"model.seed": 42,
"model.system_prompt": [
"21",
0
]
},
"_meta": {
"title": "OpenAI ChatGPT"
}
},
"21": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "You are an AI specialized in image-to-text prompt generation. Analyze the given image carefully and describe it in a detailed, structured, and prompt-friendly format. Include elements such as subject, clothing, style, environment, lighting, composition, color palette, mood, camera angle, and any other relevant visual details. Your output should resemble a high-quality text-to-image prompt that can help recreate the image. Use concise, descriptive language. Do not include explanations, just output the prompt."
},
"_meta": {
"title": "Text (Multiline)"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)