すべてのプロダクト
Search
ドキュメントセンター

Platform For AI:PAI ArtLab デベロッパーセンターの使用

最終更新日:Jun 22, 2026

このトピックでは、デベロッパーセンターを使用して ComfyUI API 統合を検証する方法を説明します。

PAI ArtLab コンソールにログオンします。

ComfyUI API 統合の検証

API 版

ComfyUI API 版を使用すると、複数の ComfyUI インスタンス間で API 呼び出しを行うことができます。このエディションは開発者による API 統合向けに設計されており、Web ベースのグラフィカルユーザーインターフェイスはありません。ComfyUI はステートフルサービスであるため、複数のインスタンスがデプロイされている場合、EAS 非同期キューサービスを使用して ComfyUI サービスを呼び出す必要があります。

前提条件

Python 環境がセットアップ済みで、非同期キュー用の EAS ソフトウェア開発キット (SDK) がインストールされていること: pip install eas_prediction

操作手順

  1. PAI ArtLab コンソールにログインします。[開発者センター] ページで、Custom Services タブをクリックし、次に [カスタムサービスの作成] をクリックします。

    Service Version には、 [ComfyUI (API Edition)] を選択します。

  2. Service StatusRunningになったら、Call Informationをクリックします。Reponse URL (Internet) タブで、リクエスト URL、トークン、エンドポイント、およびサービス ID を取得します。

    URL のドメイン名部分 (例: cn-shanghai.pai-eas.aliyuncs.com) がエンドポイントです。URL パスの最後のセグメント (例: ai4d_comfyuiapi_1u38************) がサービス ID です。非同期キュークライアントを呼び出す場合、このサービス ID の末尾に「/sink」を追加して「service_name」パラメーターを構成する必要があります。URL の横にあるコピーボタンをクリックして、アドレスをコピーします。トークンはデフォルトでアスタリスクで非表示になっています。目のアイコンをクリックしてトークンを表示します。

  3. 取得した情報に基づいて、コード内の対応する内容を置き換え、コードを実行します。

    コード例

    import requests
    ##### エンドポイント情報に基づいて、以下のパラメータを置き換えます。#####
    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 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. コードの実行後、出力からファイル名を取得します。

    send 0 success,index is b'1'
    index 1 task_id is txt2img_test
    index 1 data is b'{"status_code":200},{"type":"executed","data":{"node":"9","display_node":"9","output":{"images":[{"filename":"ComfyUI_00000000_174427782695938_599ffc33-edea-4e64-bb60-28e834940f5c_..png"}]}}}'
  5. PAI ArtLab ページで、右上隅の image アイコンにマウスカーソルを合わせ、[ストレージ] をクリックすると、OSS バケットにアクセスしてストレージパスを取得できます。

    OSS ファイルリストでは、フォルダ名 (26*/ など) とそのサブフォルダ (data-115*/) がストレージパスです。

  6. OSS 画像 URL を構築してアクセスします。形式は次のとおりです: OSS バケットパス/output/ファイル名

    たとえば、26**/data-115**************/output/ComfyUI_00000000_174427782695938_599ffc33-edea-4e64-bb60-28e834940f5c_.png

専用版

ComfyUI 専用版は、API 呼び出しと Web ベースのデバッグの両方をサポートしています。テストと検証の手順については、「API版」のセクションを参照してください。

前提条件

Python 環境がセットアップされていること。

操作手順

  1. PAI ArtLab コンソールにログインします。[開発者センター] ページで、Custom Services タブをクリックし、次に [カスタムサービスの作成] をクリックします。

    Service Version には、[ComfyUI (専用版)] を選択します。

  2. Service StatusRunningに変わったら、Call Informationをクリックします。Public network address callタブで、リクエスト URL とトークンを取得します。

    [Synchronous Call Information] ダイアログボックスには、スタンダード版サービスのみが同期呼び出しをサポートしていると表示されます。

  3. 取得した情報に基づいて、コード内の対応する内容を置き換え、コードを実行します。

    コード例

    import requests
    ##### エンドポイント情報に基づいて、以下のパラメータを置き換えます。#####
    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 Image"
                }
            }
        }
    }
    # リクエストを送信
    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}")
    # 結果を取得
    # リクエスト 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)
    # JSON 形式のデータを解析して、すべての出力から画像情報を取得
    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. コードの実行後、出力からファイル名を取得します。

    Get data:{'prompt_id':'d086402a-7454-43c5-a753-b338e4870be2','number':6,'node_errors':{}}get prompt ID:d086402a-7454-43c5-a753-b338e4870be2
    {'d086402a-7454-43c5-a753-b338e4870be2':{'prompt':[6,'d086402a-7454-43c5-a753-b338e4870be2',{'3':{'inputs':{'seed':156680208700286,'steps':20,'cfg':8.0,'sampler_name':'euler','scheduler':'normal',...}}}]}}
    Node ID: 9, Image file name: ComfyUI_00000000_174427782695938_599ffc33-edea-4e64-bb60-28e834940f5c_.png
  5. PAI ArtLab ページで、右上隅の image アイコンにカーソルを合わせ、[ストレージ] をクリックすると、OSS バケットにアクセスしてストレージパスを取得できます。

  6. OSS 画像 URL を構築してアクセスします。形式は次のとおりです: OSS バケットパス/output/ファイル名

    たとえば、26**/data-115**************/output/ComfyUI_00000000_174427782695938_599ffc33-edea-4e64-bb60-28e834940f5c_.png