comfyui的api写法
评论
收藏

comfyui的api写法

经验分享
再见史蒂夫周
2025-08-26 00:27·浏览量:682
再见史蒂夫周
发布于 2025-08-26 00:22更新于 2025-08-26 00:27682浏览



1.先运行一遍没出错

2.导出api

3.打开导出的json文件,复制内容

4.请求http开始任务

找到输入替换

请求体=请求里的body

  1. 关键词=需要生成的关键词
  2. 图片=需要上传的图片
{
  "6": {
    "inputs": {
      "text": "关键词",
      "speak_and_recognation": {
        "__value__": [
          false,
          true
        ]
      },
      "clip": [
        "38",
        0
      ]
    },
    "class_type": "CLIPTextEncode",
    "_meta": {
      "title": "CLIP Text Encode (Positive Prompt)"
    }
  },
  "8": {
    "inputs": {
      "samples": [
        "31",
        0
      ],
      "vae": [
        "39",
        0
      ]
    },
    "class_type": "VAEDecode",
    "_meta": {
      "title": "VAE解码"
    }
  },
  "31": {
    "inputs": {
      "seed": 450155265842975,
      "steps": 20,
      "cfg": 1,
      "sampler_name": "euler",
      "scheduler": "simple",
      "denoise": 1,
      "model": [
        "37",
        0
      ],
      "positive": [
        "6",
        0
      ],
      "negative": [
        "135",
        0
      ],
      "latent_image": [
        "188",
        0
      ]
    },
    "class_type": "KSampler",
    "_meta": {
      "title": "K采样器"
    }
  },
  "37": {
    "inputs": {
      "unet_name": "flux1-dev-kontext_fp8_scaled.safetensors",
      "weight_dtype": "default"
    },
    "class_type": "UNETLoader",
    "_meta": {
      "title": "UNet加载器"
    }
  },
  "38": {
    "inputs": {
      "clip_name1": "clip_l.safetensors",
      "clip_name2": "t5xxl_fp8_e4m3fn_scaled.safetensors",
      "type": "flux",
      "device": "default"
    },
    "class_type": "DualCLIPLoader",
    "_meta": {
      "title": "双CLIP加载器"
    }
  },
  "39": {
    "inputs": {
      "vae_name": "ae.safetensors"
    },
    "class_type": "VAELoader",
    "_meta": {
      "title": "加载VAE"
    }
  },
  "135": {
    "inputs": {
      "conditioning": [
        "6",
        0
      ]
    },
    "class_type": "ConditioningZeroOut",
    "_meta": {
      "title": "条件零化"
    }
  },
  "136": {
    "inputs": {
      "filename_prefix": "ComfyUI",
      "images": [
        "8",
        0
      ]
    },
    "class_type": "SaveImage",
    "_meta": {
      "title": "保存图像"
    }
  },
  "173": {
    "inputs": {},
    "class_type": "PreviewImage",
    "_meta": {
      "title": "预览图像"
    }
  },
  "188": {
    "inputs": {
      "width": 1024,
      "height": 1024,
      "batch_size": 1
    },
    "class_type": "EmptySD3LatentImage",
    "_meta": {
      "title": "空Latent图像(SD3)"
    }
  }
}
  1. 云端=comfy运行地址

请求体=上面替换好关键词和图片的json

curl -X POST "云端" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": 请求体
  }'

2.响应内容为

xbot_visual_web_service_rest_response(status_code=200, content_type='application/json', content_encoding='', content='{"prompt_id": "24c11ab9-7ac9-4b17-b1ef-836294b96c5e", "number": 8, "node_errors": {}}')

提取"prompt_id": "24c11ab9-7ac9-4b17-b1ef-836294b96c5e"为任务

5.提取内容

发送请求

云端=comfy运行地址

任务id=prompt_id

curl "云端/history/任务id"


接到响应

1.有内容

xbot_visual_web_service_rest_response(status_code=200, content_type='application/json', content_encoding='', content='{"2e480fe6-d6e9-495b-acc2-f8dffc044077": {"prompt": [4, "2e480fe6-d6e9-495b-acc2-f8dffc044077", {"3": {"inputs": {"seed": 616944802001007, "steps": 20, "cfg": 8.0, "sampler_name": "euler", "scheduler": "normal", "denoise": 1.0, "model": ["4", 0], "positive": ["6", 0], "negative": ["7", 0], "latent_image": ["5", 0]}, "class_type": "KSampler", "_meta": {"title": "K\\u91c7\\u6837\\u5668"}}, "4": {"inputs": {"ckpt_name": "v1-5-pruned-emaonly-fp16.safetensors"}, "class_type": "CheckpointLoaderSimple", "_meta": {"title": "Checkpoint\\u52a0\\u8f7d\\u5668\\uff08\\u7b80\\u6613\\uff09"}}, "5": {"inputs": {"width": 512, "height": 512, "batch_size": 1}, "class_type": "EmptyLatentImage", "_meta": {"title": "\\u7a7aLatent\\u56fe\\u50cf"}}, "6": {"inputs": {"text": "a boy", "speak_and_recognation": {"__value__": [false, true]}, "clip": ["4", 1]}, "class_type": "CLIPTextEncode", "_meta": {"title": "CLIP\\u6587\\u672c\\u7f16\\u7801"}}, "7": {"inputs": {"text": "text, watermark", "speak_and_recognation": {"__value__": [false, true]}, "clip": ["4", 1]}, "class_type": "CLIPTextEncode", "_meta": {"title": "CLIP\\u6587\\u672c\\u7f16\\u7801"}}, "8": {"inputs": {"samples": ["3", 0], "vae": ["4", 2]}, "class_type": "VAEDecode", "_meta": {"title": "VAE\\u89e3\\u7801"}}, "9": {"inputs": {"filename_prefix": "ComfyUI", "images": ["8", 0]}, "class_type": "SaveImage", "_meta": {"title": "\\u4fdd\\u5b58\\u56fe\\u50cf"}}}, {}, ["9"]], "outputs": {"9": {"images": [{"filename": "ComfyUI_00002_.png", "subfolder": "", "type": "output"}]}}, "status": {"status_str": "success", "completed": true, "messages": [["execution_start", {"prompt_id": "2e480fe6-d6e9-495b-acc2-f8dffc044077", "timestamp": 1756132916745}], ["execution_cached", {"nodes": ["3", "4", "5", "6", "7", "8", "9"], "prompt_id": "2e480fe6-d6e9-495b-acc2-f8dffc044077", "timestamp": 1756132916746}], ["execution_success", {"prompt_id": "2e480fe6-d6e9-495b-acc2-f8dffc044077", "timestamp": 1756132916746}]]}, "meta": {"9": {"node_id": "9", "display_node": "9", "parent_node": null, "real_node_id": "9"}}}}')

2.无内容

若响应内容为{},每隔5秒发送请求,直到有内容

3.提取里面的filename

http拼接下载

云端=comfyui运行地址

filename=提取的的文件名字

云端/view?filename=filename&type=output&subfolder=

6.如果需要上传图片

将加载图片换为LoadImageFromURL

打开 ComfyUI Manager → Install Custom Nodes → Search “LoadImageFromURL”

导出工作流api

找到json文件里的节点

3.图片链接=需要上传的图片

"190": {
    "inputs": {
      "image": "图片链接 ",
      "keep_alpha_channel": false,
      "output_mode": false
    },
    "class_type": "LoadImageFromUrl",
    "_meta": {
      "title": "Load Image From URL"
    }
  }
}





收藏4
全部评论1
最新
发布评论
评论