Generate AI images with "Wan2.7 Image" via direct API calls.
Quick Start
1. Configure Environment → common.md
2. Understand Capabilities → Read the core capability introduction below
3. Choose Mode → Choose one of the three operation modes according to your needs
4. Detailed Usage → image-generation-editing.md
Core Capabilities:
- ✅ Text-to-Image: Generate a single image from plain text
- ✅ Image Editing: Editing based on reference images, style transfer, multi-image fusion
- ✅ Multi-Image Generation: Text-to-multi-image, image-to-multi-image (up to 12 images)
Workflow: Unified Image Generation & Editing
graph TB
A[用户请求] --> B{是否有参考图?}
B -->|无参考图 | C[文生图/文生组图]
B -->|有参考图 | D[图生图/图像编辑/图生组图]
C --> E[调用image-generation-editing.py]
D --> E
E -->|SUCCEEDED| I[返回图片 URL]
E -->|FAILED| J[错误处理]
Process Description:
- Determine Mode - Based on whether there are reference images and the user content, choose text-to-image, image-to-image, or multi-image generation
- Preprocessing Script Execution - Automatically choose according to the input situation:
- Has a file path: Call
scripts/file_to_oss.py --fileupload the file to OSS - Has base64 data(such as the scenario of pasting in the Claw chat box): Call
scripts/file_to_oss.py --base64upload to OSS - Has resolution and aspect ratio requirements: Execute
scripts/parse_resolution.pyto get the size configuration
- Has a file path: Call
- Call Generation Script - Call
scripts/image-generation-editing.py, and fill in the corresponding parameters according to the following three operation modes - Get Results - Extract the image URL from the response (valid for 24 hours)
- Display Results - Display the image URL in the user interaction interface
- Save Image - Remind the user that the image result link has an expiration time; if the user wants to save the result for the long term, have the user specify a directory, and save the image into that directory
📖 Detailed Process and Parameters: image-generation-editing.md
Three Operation Modes
Mode 1: Image Generation (Text-to-Image)
Purpose: Generate a single image from plain text
Input: Text prompt
Output: Image
Features: No reference image input required
Key Parameters:
enable_sequential: falsen: Generation count 1size: Resolution (supports 1K/2K or custom)
📖 Detailed Description and Use Cases: image-generation-editing.md#mode-1
Mode 2: Image Editing (Image-to-Image, Style Transfer, Multi-Image Fusion)
Purpose: Editing, style transfer, or subject-consistency-preserving generation based on reference images
Input: Text prompt + 1-9 reference images
Output: Image
Features: Input 1-9 reference images for reference-based generation
Key parameters:
enable_sequential: falsen: Number to generate 1size: Resolution (supports 1K/2K or custom)
📖 Detailed description and use cases: image-generation-editing.md#mode-2
Mode 3: Group image generation
Purpose: Generate a series of images based on a text description (generate multiple related images at once, tutorials, stories, etc.)
Input: Text prompt + optional reference images (up to 9)
Output: Up to 12 images
Features: Generate multiple related images at once; the actual number is determined by the model
Key parameters:
enable_sequential: truen: Number to generate range [1-12]size: Resolution (supports 1K/2K or custom)
📖 Detailed description and use cases: image-generation-editing.md#mode-3
Documents Structure
📖 Common Configuration
Purpose: General configuration and environment variable management
Contents:
- API Key acquisition and configuration steps
- Environment variable configuration (DASHSCOPE_API_KEY, DASHSCOPE_BASE_URL)
- Region selection (Beijing, Singapore)
When to consult: When configuring the environment for the first time or when configuration needs to be modified
📖 Image Generation & Editing
Purpose: Wan 2.7 unified skill detailed documentation
Contents:
- Detailed descriptions and use cases of the three operation modes (Mode 1/2/3)
- Image input requirements (format, resolution, size, aspect ratio)
- Instructions for using the resolution conversion script (parse_resolution.py)
When to consult: When you need to understand specific API usage, parameter configuration, or troubleshoot issues
📖 Upload to OSS
Purpose: Python script for uploading local files or base64 image data to temporary OSS storage
Contents:
- File upload function implementation
- Obtain oss:// URL
- Supports both file path and base64 input methods
- Supports all scenarios requiring local files; if the user pastes reference images in the chat box, please pass these reference images to the script in base64 form
When to consult: When you need to upload local images for image-to-image, image editing, or image-to-group-image generation
Usage example:
# 方式 1: 从文件路径上传
python scripts/file_to_oss.py --file /tmp/image.jpg --model wan2.7-image
# 方式 2: 从 base64 数据上传(OpenClaw 场景)
python scripts/file_to_oss.py --base64 "<base64_data>" --model wan2.7-image
# 输出:oss://dashscope-instant/xxx/cat.png
📖 Parse resolution
Purpose: Parse the resolution description input by the user and convert it to the size parameter required by the API.
Contents:
- The user input contains resolution, 1K, 2K, 2:4, and other related content
- K + ratio:
"2K 3:4","1K 16:9" - K value only:
"1K","2K"(default 1:1) - Direct specification:
"1024*1024","2048*2048"
When to consult: When you need to parse the user's resolution requirements (e.g., when the user has requirements for both resolution and aspect ratio, parse the resolution description input by the user), convert and use
Usage example:
python scripts/parse_resolution.py "2K 3:4"
# 输出:1774*2364
📖 Generation tasks taking too long and asynchronous task querying
When to use: When the time taken by the user's call to scripts/image-generation-editing.py is too long, the script will not wait for the final output result and will proactively output a task_id. Afterward, every 10 seconds use the scripts/check_wan_task_status.py script to query the status of the task corresponding to that task_id. Query 3 times in a row. If a url is output, it means the task has finally completed; if it is still in progress, display the task_id and prompt the user to query again later using the task_id.
Important principles If multiple queries still show that generation is in progress (RUNNING), inform the user of the task_id and prompt the user to query again later using the task_id. Absolutely do not change the user's requirements on your own, for example by reducing the number of reference images or the number of generated collage images.
Usage example:
python scripts/check_wan_task_status.py "<task_id>"
Error Handling
Common errors and solutions:
| Error | Cause | Solution |
|---|---|---|
| API key not provided | API Key not set | Set DASHSCOPE_API_KEY environment variable |
| Request failed: code=XXX | API call failed | Check the network connection, API Key validity, and model availability |
| Failed to parse response | Abnormal response format | View the raw response and refer to the DashScope documentation |
Detailed error code reference:DashScope error code documentation
Related Documents
- 📖 common.md - Documentation for environment configuration
- 📖 image-generation-editing.md - Documentation for details and examples of text-to-image/image-to-image/editing/collage generation
- 🐍 file_to_oss.py - Local file upload script
- 🐍 parse_resolution.py - Script for parsing the resolution input by the user
- 🐍 image-generation-editing.py - Script for text-to-image/image-to-image/editing/collage generation