Integrate the Wan (ComfyUI) service deployed on PAI-EAS into Dify to automate complex content creation workflows. This topic describes how to deploy and integrate the service for end-to-end text-to-multimedia content generation.
Solution overview
The core of this solution is to use Dify as an application orchestrator to call the ComfyUI inference service deployed on PAI-EAS. ComfyUI inference tasks are executed asynchronously. The entire call chain is as follows:
Submit a task: Dify sends a POST request to the EAS service. The request body contains the ComfyUI workflow in JSON format. When EAS receives the task, it immediately returns a unique
prompt_id.Poll the status: Dify uses the
prompt_idfrom the previous step to poll the task execution status by sending GET requests. EAS returns the task status, such as completed, successful, or failed.Retrieve the result: After you confirm that the task is successfully executed, you can send another GET request to retrieve the final result. This result contains the filename of the generated file on Object Storage Service (OSS). Dify concatenates the filename with the OSS endpoint and displays the complete image or video link.
The following figure shows the complete workflow.

Step 1: (Optional) Deploy Dify
If you already have a Dify environment, you can skip this section. This topic uses the deployment of Dify Community Basic Edition on Compute Nest as an example.
You can go to the Dify Community Edition product page on Compute Nest and click Deploy Now.
Select configurations as needed. For a basic demo, select the Single ECS Version template, set Instance Type to
ecs.u1-c1m2.xlarge, set an instance password, and select a zone.Click Next: Confirm Order, and then click Create Now on the next page.
After the service is deployed, click Details. In the Use Now section on the Overview tab, find the Dify access link. You can then register an account and log on to create a Dify application.

Step 2: Deploy Wan ComfyUI
Go to ModelGallery. In the search box, enter Wan 2.1-Text-to-Video-1.3B and click the card to open the model's product page.
In the upper-right corner, click Deploy. On the configuration page, configure the following parameters and leave the other parameters at their default values.
Set Deployment Method to .
For Service Configuration, in the JSON editor, set the
storage.oss.pathparameter to your OSS path, such asoss://examplebucket/wan. This path is the working directory where ComfyUI stores generated content. For more information about OSS operations, see Quick Start for the OSS console.
Click Deploy. The deployment is complete in about 3 minutes when the service status changes to Running.
On the Service Details page, click View Invocation Information. Obtain the public endpoint and token for the EAS service. This information is required to call the service in Dify.

Step 3: Create a Dify application
In Dify, import the sample DSL file wan-comfyui-dify.yml. This topic uses this file to explain the key node settings for calling the ComfyUI service.

1. Set environment variables
OSS_URL: The access path of the generated files. In this topic, the ComfyUI working directory is
oss://examplebucket/wan. Therefore, set the URL tohttps://examplebucket.oss-cn-hangzhou.aliyuncs.com/wan/output. In this URL,oss-cn-hangzhou.aliyuncs.comis the public endpoint for OSS in the China (Hangzhou) region. For other regions, see OSS regions and endpoints.EAS_Token: The service token obtained in Step 2.
EAS_URL: The public endpoint of the service obtained in Step 2.

2. Set input variables in the start node
Set dynamic parameters, such as positive and negative prompts, as variables to be entered for each call.

3. Configure the POST request (get the prompt ID)
3.1 Set the request address
Append `/prompt` to the `EAS_URL` to create the POST request address.

3.2 Construct and send the POST request
Configure the URL, HEADERS, and BODY. The BODY is the exported ComfyUI workflow in JSON format. For information about how to create and export the JSON, see Use the WebUI. Replace parameters that require dynamic modification, such as prompts and seed numbers, with variables from Dify.

3.3 Get the prompt ID
Extract the prompt_id from the response. This ID is used later to poll for the result.
def main(arg: str) -> dict:
data = json.loads(arg)
return {"result": data["prompt_id"]}
4. Configure the polling logic (get the inference result)
Use the `prompt_id` to periodically send GET requests to check the task status.
4.1 Set the request address
Append history/<prompt_id> to the `EAS_URL` to create the GET request address. <prompt_id> is the ID retrieved in the previous step.

4.2 Send a GET request based on the prompt_id

4.3 Add a delay
Insert a code node between each polling request to execute an operation, such as time.sleep(12). This prevents excessively frequent requests.
import time
def main()-> dict:
time.sleep(12)
return {
"result": ""
}
4.4 Determine if execution is complete
If the response contains the `prompt_id`, the inference is complete.

5. Concatenate the file address and display the result
After the task is complete, extract the filename from the final polling result and concatenate it with the `OSS_URL` from the environment variables. This creates a publicly accessible file link, which is then displayed in the End node of the Dify workflow.
5.1 Get the inference result
The configuration of this node is the same as that of the node in Section 4.2.

5.2 Extract the filename
import json
def main(input_str: str) -> dict:
data = json.loads(input_str)
images = []
image_names = []
first_key = next(iter(data))
status = data[first_key]["status"]
if status["completed"] and status["status_str"] == "success":
images = data[first_key]["outputs"]["28"]["images"]
for img in images:
image_names.append(img["filename"])
# Convert the list to a string
image_names_str = ",".join(image_names)
return {
"result": image_names_str,
}
5.3 Concatenate the file access address
Append the filename to the `OSS_URL` to create a publicly accessible link and display it in the Dify application result.
Ensure that the OSS bucket permission is set to public-read. For more information, see Bucket ACL.


Step 4: Test the application
In Dify, click Preview in the upper-right corner. Enter the positive and negative prompts. Enter `1` in the dialog box. The workflow does not use this field, so you can enter any value. After you send the request, wait for the video to be generated.

Recommendations for production applications
Security: In a production environment, setting an OSS bucket to public-read creates a data security risk. You can restrict access to specific IP addresses or VPCs. For more information, see Bucket Policy.
Stability and cost: Set a reasonable waiting time for polling. A short interval increases the number of API calls and the server load, which can result in unnecessary costs. A long interval increases the user waiting time. You can adjust the interval based on the average execution time of your tasks.
FAQ
Why can't I access the generated image or video link?
Check the following:
Check whether the OSS bucket permission is set to public-read.
Check whether the `OSS_URL` environment variable in Dify is correctly configured. You must also verify that the OSS domain name matches the region where the bucket is located.
What should I do if the workflow is stuck at the polling step?
This issue usually occurs because the task on the EAS server failed to complete. You can log on to the PAI console and view the real-time log of the EAS service to check for runtime errors.