4Z API

Coze Workflow: Input to URL

If you have Coze VIP, you can download and import the workflow directly

https://wwaod.lanzn.com/b011lwl8ij Password: 3qnp

Simple loop workflow (Sora2 example): text + image input to final URL (overview below)

企业微信截图_17677735722402.png

1. Start

企业微信截图_1767773636845.png

Add input variables for prompt and image based on the API parameters. Add more inputs if needed.

2. Call the model (add an HTTP node)

企业微信截图_17677740268061.png

Configure the HTTP request from the docs:

  1. First red box: method and URL
  2. Second red box: headers
  3. Third: body. Pick the format from the docs (JSON in this example). Fields marked "Start" come from earlier inputs; type {} while editing to pick them.

3. Parse the response for taskId (add a Code node)

企业微信截图_17677742429398.png

As shown, bind the previous HTTP body as the input variable. Parse the body to get id (JavaScript in this example):

async function main({ params }: Args): Promise<Output> {
    // 1. Read body string from params.input
    // Assume params.input is the full HTTP response body
    const bodyStr = params.input;

    // 2. Parse JSON body string "{\"id\":...}"
    let taskId = "";
    try {
        const bodyObj = JSON.parse(bodyStr);
        taskId = bodyObj.id;
    } catch (e) {
        // Avoid crashing on parse failure
        console.log("JSON parse failed:", e);
    }

    // 3. Return taskId
    const ret = {
        "taskId": taskId
    };

    return ret;
}

Output variable names must match the keys in ret.

4. Loop the query API until you get a URL (add a Loop node)

1. Configure the loop (this example uses an infinite loop with break conditions)

企业微信截图_17677745518897.png

Intermediate variable: taskId from the previous code node. Outputs: URL and status.

2. Inside the loop, add an HTTP node to query the task

企业微信截图_17677753812075.png

Body parameters follow the model's query-task docs.

3. Add a Code node to read URL and status

企业微信截图_17677755174326.png

Input is the query response body:

async function main({ params }: Args): Promise<Output> {
    // 1. Read body string from params.input
    const bodyStr = params.input;

    // 2. Parse JSON
    let url = "";
    let status = "";
    try {
        const bodyObj = JSON.parse(bodyStr);
        url = bodyObj.video_url;
        status = bodyObj.status;
    } catch (e) {
        // Avoid crashing on parse failure
        console.log("JSON parse failed:", e);
    }

    // 3. Return url + status
    const ret = {
        "url": url,
        "status": status
    };

    return ret;
}

4. Add an If node to decide whether the query got a URL

企业微信截图_17677757634138.png

Branch 1: previous code node's url is empty or not. Branch 2: status is failed.

5. Act on the If result

企业微信截图_17677758794115.png

企业微信截图_17677761996893.png

Add a Break loop node when either success branch hits. Add a Wait then Continue loop when both checks are false (avoid request storms; ~1500ms is a good wait).

5. Process loop output (add a Code node)

Loop output is an array; keep only the last values:

async function main({ params }: Args): Promise<Output> {

    // Inputs
    const urls = params.urls;
    const statuss = params.statuss;

    // Return last url/status
    const ret = {
        "url": urls[urls?.length -1],
        "status": statuss[statuss?.length -1]
    };

    return ret;
}

Outputs: processed URL and status

6. Decide success/failure from whether URL has a value

企业微信截图_17677764885854.png

7. Final output

企业微信截图_17677765862529.png

企业微信截图_17677765941365.png

Emit success/failure text or variables as needed; you can also output on an End node.

8. Result demo

企业微信截图_17677770925315.png