All Products
Search
Document Center

Platform For AI:Developer Center

Last Updated:Dec 10, 2025

This topic describes how to use the Developer Center to verify ComfyUI API integration.

Verify ComfyUI API integration

API edition

ComfyUI API edition is used for API calls in multi-ComfyUI instance scenarios. It is designed for developers to implement integration, and has no web graphical interface. Because ComfyUI is a stateful service, in multi-ComfyUI instance scenarios, use an asynchronous queue service of EAS to properly call the ComfyUI service.

Prerequisites

You have a Python environment and have installed the EAS SDK (for asynchronous queue service): pip install eas_prediction

Procedure

  1. Log on to the PAI ArtLab console. Choose Developer Center in the left-side navigation pane and click the Custom Service tab. Then, click Create Custom Service.

    Select ComfyUI (API Edition) for Service Edition.

  2. When the Status changes to Running, click Call Information. On the Response URL (Internet) tab, get the URL, token, endpoint, and service ID.

    image

  3. Replace the corresponding content in the code with the call information you just got, and run the sample code.

    Sample code

    import requests
    
    ##### Replace the following parameters based on the call information #####
    input_url = "http://115************.cn-shanghai.pai-eas.aliyuncs.com/api/predict/ai4d_comfyuiapi_1u38************"
    token = "Yjha************"
    endpoint = "115************.cn-shanghai.pai-eas.aliyuncs.com"
    service_name = "ai4d_comfyuiapi_1u38************/sink"
    ################################
    
    session = requests.session()
    session.headers.update({"Authorization": f"{token}"})
    
    work_flow = {
        "3": {
            "inputs": {
                "seed": 156680208700286,
                "steps": 20,
                "cfg": 8,
                "sampler_name": "euler",
                "scheduler": "normal",
                "denoise": 1,
                "model": [
                    "4",
                    0
                ],
                "positive": [
                    "6",
                    0
                ],
                "negative": [
                    "7",
                    0
                ],
                "latent_image": [
                    "5",
                    0
                ]
            },
            "class_type": "KSampler",
            "_meta": {
                "title": "K sampler"
            }
        },
        "4": {
            "inputs": {
                "ckpt_name": "3dAnimationDiffusion_v10.safetensors"
            },
            "class_type": "CheckpointLoaderSimple",
            "_meta": {
                "title": "Checkpoint loader (simple)"
            }
        },
        "5": {
            "inputs": {
                "width": 512,
                "height": 512,
                "batch_size": 1
            },
            "class_type": "EmptyLatentImage",
            "_meta": {
                "title": "Empty Latent"
            }
        },
        "6": {
            "inputs": {
                "text": "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,",
                "clip": [
                    "4",
                    1
                ]
            },
            "class_type": "CLIPTextEncode",
            "_meta": {
                "title": "CLIP text encoder"
            }
        },
        "7": {
            "inputs": {
                "text": "text, watermark",
                "clip": [
                    "4",
                    1
                ]
            },
            "class_type": "CLIPTextEncode",
            "_meta": {
                "title": "CLIP text encoder"
            }
        },
        "8": {
            "inputs": {
                "samples": [
                    "3",
                    0
                ],
                "vae": [
                    "4",
                    2
                ]
            },
            "class_type": "VAEDecode",
            "_meta": {
                "title": "VAE decoding"
            }
        },
        "9": {
            "inputs": {
                "filename_prefix": "ComfyUI",
                "images": [
                    "8",
                    0
                ]
            },
            "class_type": "SaveImage",
            "_meta": {
                "title": "Save the image"
            }
        }
    }
    
    for i in range(1):
        payload = work_flow
        response = session.post(url=f'{input_url}/api_prompt?task_id=txt2img_test', json=payload)
        if response.status_code != 200:
            exit(f"send request error:{response.content}, response code:{response.status_code}")
        else:
            print(f"send {i} success, index is {response.content}")
    
    
    from eas_prediction import QueueClient
    
    sink_queue = QueueClient(f'{endpoint}', f'{service_name}')
    sink_queue.set_token(f'{token}')
    sink_queue.init()
    
    watcher = sink_queue.watch(0, 1, auto_commit=False)
    for x in watcher.run():
        if 'task_id' in x.tags:
            print('index {} task_id is {}'.format(x.index, x.tags['task_id']))
            print(f'index {x.index} data is {x.data}')
            sink_queue.commit(x.index)
    
  4. After running the code, get the file name from the results.

    image

  5. In the ArtLab, hover over image in the upper-right corner. Click the link next to Storage to go to the OSS bucket and get the storage path.

    image

  6. Concatenate the OSS image address and access it. Format: OSS bucket path/output/file name

    For example, 26****/data-115****************/output/ComfyUI_00000000_174427782695938_599ffc33-edea-4e64-bb60-28e834940f5c_.png

Exclusive edition

ComfyUI exclusive edition supports both API calls and online debugging. The verification process is similar to that of the API edition.

Prerequisites

You have a Python environment.

Procedure

  1. Log on to the PAI ArtLab console. Choose Developer Center in the left-side navigation pane and click the Custom Service tab. Then, click Create Custom Service.

    Select ComfyUI (Exclusive edition) for Service Edition.

  2. When the Service Status changes to Running, click Call Information. On the Internet Endpoint tab, get the URL and token.

    image

  3. Replace the corresponding content in the code with the call information you just got, and run the sample code.

    Sample code

    import requests
    
    ##### Replace the following parameters based on the debug information #####
    url = "http://ai4d_comfyuiapi_1u38************.115************.cn-shanghai.pai-eas.aliyuncs.com/"
    token = "Yjha************"
    ################################
    
    payload = {
        "prompt": {
            "3": {
                "inputs": {
                    "seed": 156680208700286,
                    "steps": 20,
                    "cfg": 8,
                    "sampler_name": "euler",
                    "scheduler": "normal",
                    "denoise": 1,
                    "model": [
                        "4",
                        0
                    ],
                    "positive": [
                        "6",
                        0
                    ],
                    "negative": [
                        "7",
                        0
                    ],
                    "latent_image": [
                        "5",
                        0
                    ]
                },
                "class_type": "KSampler",
                "_meta": {
                    "title": "K sampler"
                }
            },
            "4": {
                "inputs": {
                    "ckpt_name": "3dAnimationDiffusion_v10.safetensors"
                },
                "class_type": "CheckpointLoaderSimple",
                "_meta": {
                    "title": "Checkpoint loader (simple)"
                }
            },
            "5": {
                "inputs": {
                    "width": 512,
                    "height": 512,
                    "batch_size": 1
                },
                "class_type": "EmptyLatentImage",
                "_meta": {
                    "title": "Empty Latent"
                }
            },
            "6": {
                "inputs": {
                    "text": "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,",
                    "clip": [
                        "4",
                        1
                    ]
                },
                "class_type": "CLIPTextEncode",
                "_meta": {
                    "title": "CLIP text encoder"
                }
            },
            "7": {
                "inputs": {
                    "text": "text, watermark",
                    "clip": [
                        "4",
                        1
                    ]
                },
                "class_type": "CLIPTextEncode",
                "_meta": {
                    "title": "CLIP text encoder"
                }
            },
            "8": {
                "inputs": {
                    "samples": [
                        "3",
                        0
                    ],
                    "vae": [
                        "4",
                        2
                    ]
                },
                "class_type": "VAEDecode",
                "_meta": {
                    "title": "VAE decoding"
                }
            },
            "9": {
                "inputs": {
                    "filename_prefix": "ComfyUI",
                    "images": [
                        "8",
                        0
                    ]
                },
                "class_type": "SaveImage",
                "_meta": {
                    "title": "Save the image"
                }
            }
        }
    }
    
    # Initiate a request
    session = requests.session()
    session.headers.update({"Authorization": f"{token}"})
    prompt_url = url + "prompt"
    
    response = session.post(url=f'{prompt_url}', json=payload)
    if response.status_code != 200:
        raise Exception(response.content)
    
    data = response.json()
    prompt_id = data['prompt_id']
    print(f"get data: {data}, get prompt id: {prompt_id}")
    
    
    # Get results
    # Construct request URL
    history_url = f"{url}history/{prompt_id}"
    
    session = requests.session()
    session.headers.update({"Authorization": f"{token}"})
    
    response = session.get(url=f'{history_url}')
    
    if response.status_code != 200:
        raise Exception(response.content)
    
    data = response.json()
    print(data)
    
    # Parse JSON data to get image information for all outputs
    for prompt_id, prompt_data in data.items():
        outputs = prompt_data.get("outputs", {})
        for node_id, node_data in outputs.items():
            images = node_data.get("images", [])
            for image in images:
                filename = image.get("filename")
                print(f"Node number: {node_id}, Image filename: {filename}")
    
  4. After running the code, get the file name from the results.

    image

  5. In the ArtLab, hover over image in the upper-right corner. Click the link next to Storage to go to the OSS bucket and get the storage path.

    image

  6. Concatenate the OSS image address and access it. Format: OSS Bucket path/output/file name

    For example, 26****/data-115****************/output/ComfyUI_00000000_174427782695938_599ffc33-edea-4e64-bb60-28e834940f5c_.png