All Products
Search
Document Center

Platform For AI:PAI ArtLab Developer Center guide

Last Updated:Aug 14, 2025

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

Log on to the PAI ArtLab console.

Verify ComfyUI API integration

API edition

The API Edition of ComfyUI is designed for developers to make API calls across multiple ComfyUI instances. It does not have a web-based graphical user interface. Because ComfyUI is a stateful service, you must use the asynchronous queue service of Elastic Algorithm Service (EAS) to call the ComfyUI service when you are using multiple ComfyUI instances.

Prerequisites

You have a Python environment and have installed the EAS software development kit (SDK) dependency for the asynchronous queue: pip install eas_prediction

Procedure

  1. Log on to the PAI ArtLab console. On the Developer Center page, click the Custom Service tab, and then click Create Custom Service.

    Set Service Version to ComfyUI (API Edition).

  2. Wait until the Service Status changes to Running. Click Call Information. On the Request URL (Internet) tab, obtain the request URL, token, endpoint, and service ID.

    image

  3. Replace the corresponding parameters in the code with the call information that you obtained, and then run the 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 Decoder"
            }
        },
        "9": {
            "inputs": {
                "filename_prefix": "ComfyUI",
                "images": [
                    "8",
                    0
                ]
            },
            "class_type": "SaveImage",
            "_meta": {
                "title": "Save 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 the code runs, retrieve the file name from the output.

    image

  5. On the PAI ArtLab page, hover the mouse pointer over the image icon in the upper-right corner. Click Storage to access the OSS bucket and obtain the storage path.

    image

  6. Construct the OSS image URL and access it. Use the following format: OSS bucket path/output/file name

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

Exclusive edition

The Exclusive Edition of ComfyUI supports both API calls and web-based debugging. For the verification process, see the API Edition section.

Prerequisites

You have a Python environment.

Procedure

  1. Log on to the PAI ArtLab console. On the Developer Center page, click the Custom Service tab, and then click Create Custom Service.

    Set Service Version to ComfyUI (Exclusive Edition).

  2. Wait until the Service Status changes to Running. Click Call Information. On the Internet Endpoint tab, obtain the request URL and token.

    image

  3. Replace the corresponding parameters in the code with the call information that you obtained, and then run the 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 Decoder"
                }
            },
            "9": {
                "inputs": {
                    "filename_prefix": "ComfyUI",
                    "images": [
                        "8",
                        0
                    ]
                },
                "class_type": "SaveImage",
                "_meta": {
                    "title": "Save Image"
                }
            }
        }
    }
    
    # Send the 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 the result.
    # Construct the 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 the JSON-formatted data to get the image information from 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 ID: {node_id}, Image file name: {filename}")
    
  4. After the code runs, retrieve the file name from the output.

    image

  5. On the PAI ArtLab page, hover the mouse pointer over the image icon in the upper-right corner. Click Storage to access the OSS bucket and obtain the storage path.

    image

  6. Construct the OSS image URL and access it. Use the following format: OSS bucket path/output/file name

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