Create and Run a Text-to-Image Workflow in Coze: Step-by-Step Guide
This tutorial walks you through logging into Coze, building a text‑to‑image workflow with start, image generation, and end nodes, testing and publishing it, then generating a personal access token and invoking the workflow via the Coze API to retrieve the image URL.
First, log into Coze (https://www.coze.cn/), go to Workspace / Resource Library, and create a new workflow named text2image (English only) with a description.
The workflow consists of a start node and an end node.
2.1 Add Image Generation Node
2.2 Connect Nodes
Link the start node to the image generation node and then to the end node.
2.3 Configure Image Generation Node
Model: portrait
Aspect ratio: 1:1
Input: add a variable and select “Start” as its value
Prompt: use {{variable_name}} to reference the variable
2.4 Configure End Node
Set the output to return the data field from the image generation node.
3 Test the Workflow
Run the workflow to verify it works. Adjust the input prompt (e.g., “a long‑haired woman in yoga pants standing next to a golf car”) until the generated image matches the description. If the output is empty, the generation failed and you should retry.
4 Publish the Workflow
After publishing, the workflow details page shows the workflow ID, for example workflow_id=7529898597627412506.
5 Coze API
5.1 Add Personal Access Token
Create a token by giving it a name, setting an expiration time, choosing the required permissions, and selecting the workspace. Copy the generated token (e.g.,
pat_b4hgp9Rn6iMYZUSmbTZih6YHdEkvNwZTm5SLja2aUIrdhL4jkIFvVvOKOGMmfZox) because it cannot be retrieved later.
5.2 Run the API
Send a request containing the token, the workflow ID, and the required input parameters for the start node. The API returns a JSON object whose data field contains the image URL.
{
"code":0,
"cost":"0",
"data":"{output":"https://s.coze.cn/t/WkLTawwU0H4/"}",
"debug_url":"https://www.coze.cn/work_flow?execute_id=7529910616715886601&space_id=7529344229806686244&workflow_id=7529898597627412506&execute_mode=2",
"msg":"Success",
"token":0
}Paste the output URL into a browser to view the generated image.
AI Software Product Manager
Daily updates of Xiaomi's latest AI internal materials
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
