跳转至

快速开始

本指南将帮助你在几分钟内开始使用 ComfyKit。

方案一:RunningHub 云端(无需 GPU)⭐

如果你没有本地 GPU 或 ComfyUI 环境,使用 RunningHub 云平台:

import asyncio
from comfykit import ComfyKit

async def main():
    # 使用 RunningHub 初始化(只需 API key)
    kit = ComfyKit(
        runninghub_api_key="your-runninghub-key"
    )

    # 使用 workflow ID 执行
    result = await kit.execute("12345", {
        "prompt": "a beautiful sunset over the ocean"
    })

    print(f"🖼️  生成的图片: {result.images}")

asyncio.run(main())

获取 API Key

RunningHub 免费获取 API key

方案二:本地 ComfyUI

如果你有本地运行的 ComfyUI:

1. 启动 ComfyUI

# 启动 ComfyUI(默认端口 8188)
python main.py

2. 执行 workflow

import asyncio
from comfykit import ComfyKit

async def main():
    # Connect to local ComfyUI (default: http://127.0.0.1:8188)
    kit = ComfyKit(comfyui_url="http://127.0.0.1:8188")

    # 执行 workflow
    result = await kit.execute(
        "workflow.json",
        params={"prompt": "a cute cat playing with yarn"}
    )

    # 检查结果
    if result.status == "completed":
        print(f"✅ 成功!耗时: {result.duration:.2f}秒")
        print(f"🖼️  图片: {result.images}")
    else:
        print(f"❌ 失败: {result.msg}")

asyncio.run(main())

💡 提示comfyui_url 默认为 http://127.0.0.1:8188,可省略此参数

理解返回结果

当你执行一个 workflow 时,ComfyKit 会返回一个 ExecuteResult 对象:

result = await kit.execute("workflow.json", {"prompt": "a cat"})

# 基本信息
print(result.status)          # "completed" 或 "failed"
print(result.duration)        # 执行耗时(秒)
print(result.prompt_id)       # 唯一执行 ID

# 生成的媒体文件
print(result.images)          # 图片 URL 列表
print(result.videos)          # 视频 URL 列表
print(result.audios)          # 音频 URL 列表

# 按变量名分组
print(result.images_by_var)   # 按输出变量分组的图片字典

下一步