跳转到主要内容
PR #8041开始,ComfyUI 支持通过你的 ComfyUI 账户 API 密钥直接使用内置的付费合作节点,无需特定的前端界面(甚至可以完全不使用前端)。 这意味着你可以创建工作流来组合:
  • 本地操作系统模型
  • 自定义节点社区的工具
  • 流行的付费模型
然后通过将 prompt 发送到 Comfy webserver API 来一起运行所有内容,由它处理所有的协调工作。 这对于希望将 Comfy 用作后端服务、通过命令行运行、或使用自有前端等用户都很有帮助。

前提条件

使用你的 ComfyUI 账户 API 密钥来调用付费合作节点需要:
重要提示: 本文介绍的是ComfyUI 账户 API 密钥,用于在工作流中访问付费合作节点。如果你想向注册表发布自定义节点,请参见发布节点
要使用你的 ComfyUI 账户 API 密钥来调用付费合作节点,你需要在 ComfyUI Platform 上注册一个账户,然后创建 API 密钥 你需要确保你的 ComfyUI 账户有足够的积分来测试对应的功能。

积分

请参考积分章节了解如何为你的账户购买积分

Python 示例

以下是一个如何通过 Python 代码向 ComfyUI API 发送包含合作节点的工作流的示例:
"""在无头模式或使用替代前端运行 ComfyUI 时使用合作节点

你可以通过在 prompt 中包含 API 密钥来执行包含合作节点的 ComfyUI 工作流。
API 密钥需要添加到 payload 的 `extra_data` 字段中。
下面我们展示一个如何实现的示例。

更多信息请参考:

- 合作节点概述: https://docs.comfy.org/zh/tutorials/partner-nodes/overview
- 要生成 API 密钥,请登录这里: https://platform.comfy.org/login
"""

import json
from urllib import request

SERVER_URL = "http://127.0.0.1:8188"

# 我们有一个包含合作节点的 prompt/job(API 格式的工作流)。
workflow_with_api_nodes = """{
  "11": {
    "inputs": {
      "prompt": "A dreamy, surreal half-body portrait of a young woman meditating. She has a short, straight bob haircut dyed in pastel pink, with soft bangs covering her forehead. Her eyes are gently closed, and her hands are raised in a calm, open-palmed meditative pose, fingers slightly curved, as if levitating or in deep concentration. She wears a colorful dress made of patchwork-like pastel tiles, featuring clouds, stars, and rainbows. Around her float translucent, iridescent soap bubbles reflecting the rainbow hues. The background is a fantastical sky filled with cotton-candy clouds and vivid rainbow waves, giving the entire scene a magical, dreamlike atmosphere. Emphasis on youthful serenity, whimsical ambiance, and vibrant soft lighting.",
      "prompt_upsampling": false,
      "seed": 589991183902375,
      "aspect_ratio": "1:1",
      "raw": false,
      "image_prompt_strength": 0.4000000000000001,
      "image_prompt": [
        "14",
        0
      ]
    },
    "class_type": "FluxProUltraImageNode",
    "_meta": {
      "title": "Flux 1.1 [pro] Ultra Image"
    }
  },
  "12": {
    "inputs": {
      "filename_prefix": "ComfyUI",
      "images": [
        "11",
        0
      ]
    },
    "class_type": "SaveImage",
    "_meta": {
      "title": "Save Image"
    }
  },
  "14": {
    "inputs": {
      "image": "example.png"
    },
    "class_type": "LoadImage",
    "_meta": {
      "title": "Load Image"
    }
  }
}"""


prompt = json.loads(workflow_with_api_nodes)
payload = {
    "prompt": prompt,
    # 将 `api_key_comfy_org` 添加到 payload 中。
    # 如果你需要处理多个客户端,可以先从关联的用户获取密钥。
    "extra_data": {
        "api_key_comfy_org": "comfyui-87d01e28d*******************************************************"  # 替换为实际的密钥
    },
}
data = json.dumps(payload).encode("utf-8")
req = request.Request(f"{SERVER_URL}/prompt", data=data)

# 发送请求
request.urlopen(req)

相关文档