---
name: sophnet-image-generate
description: Use when a user requests Sophnet text-to-image generation, needs model selection across Z-Image-Turbo/Qwen-Image/Qwen-Image-Plus, or reports polling/output issues such as missing IMAGE_URL.
metadata:
  short-description: Generate Sophnet images with stable polling outputs
---

# Sophnet Image Generate

## Overview

Generate Sophnet images with Python scripts that handle task polling and structured output.

Script: `generate_image.py` — API 调用与轮询，输出 `TASK_ID`、`STATUS`、`IMAGE_URL`。

## When to Use

- User asks to generate an image with Sophnet models.
- Prompt includes model choice (`Z-Image-Turbo`, `Qwen-Image`, `Qwen-Image-Plus`).
- Do not use when the task is only to display an existing image URL/path; use `sophnet-smart-image-loader`.

## Quick Reference

| Goal     | Command                                                                                |
| -------- | -------------------------------------------------------------------------------------- |
| Generate | `uv run --project {baseDir} python {baseDir}/scripts/generate_image.py --prompt "..."` |
| Options  | `uv run --project {baseDir} python {baseDir}/scripts/generate_image.py --help`         |

## Implementation

1. Run the script with `--prompt` (and optional `--model`, `--size`, `--n` etc.).
2. Parse the stdout output: extract every line matching `IMAGE_URL=<url>`.
3. **Output format (mandatory):**
   - **First:** Output the original prompt used for generation, e.g. `**Prompt:** <the exact prompt string passed to --prompt>`.
   - **Then:** For each extracted URL, present it as a Markdown image: `![image](<url>)`. If multiple URLs, output one per line.

Example (single image):

```
**Prompt:** 一只在星空下奔跑的柴犬

![image](https://example.com/generated/abc123.png)
⚠️**提示**: 本内容有AI生成，图片保存24小时，请及时下载保存！
```

Example (multiple images):

```
**Prompt:** 赛博朋克风格的城市夜景

![image](https://example.com/generated/abc123.png)
![image](https://example.com/generated/def456.png)
⚠️**提示**: 本内容有AI生成，图片保存24小时，请及时下载保存！
```

Do **not** output raw `IMAGE_URL=...` lines, JSON, or other internal format to the user. User-facing output must be: prompt line + Markdown image(s) only.

## Common Mistakes

- Forgetting to output the original **Prompt:** line before the image(s).
- Returning raw `IMAGE_URL=...` lines instead of Markdown image syntax.
- Wrapping the URL in extra quotes or angle brackets — use `![image](URL)` exactly.
