Based on the text-to-image and text-to-video capabilities of Volcano Engine Jimeng AI, it supports generating images and videos from text descriptions.
Features
- Execution process storage: Uses MD5(prompt) as the folder name to save task status
- Asynchronous query: Supports resumable execution to avoid resubmitting the same task
- Base64 image processing: Decodes and saves images directly from the API response
- Supports Jimeng AI text-to-image (v3.0 / v3.1 / v4.0)
- Supports Jimeng AI text-to-video (v3.0 1080P)
- Configurable aspect ratio, generation count, and custom dimensions
Required Environment Variables
| Variable Name | Required | Description |
|---|---|---|
VOLCENGINE_AK |
Required | Volcano Engine Access Key |
VOLCENGINE_SK |
Conditionally required | Volcano Engine Secret Key (required for permanent credentials) |
VOLCENGINE_TOKEN |
Optional | Security token (required for temporary credentials STS) |
Note: When using temporary credentials (starting with AKTP), you can use only AK + Token, and SK is not required.
Configuration Example
export VOLCENGINE_AK="your-access-key"
export VOLCENGINE_SK="your-secret-key"
# 如果使用临时凭证(STS),还需要设置 Token
export VOLCENGINE_TOKEN="your-security-token"
How to obtain:
- Log in to Volcano Engine Console
- Go to "Access Control" -> "Key Management"
- Create or view an existing access key
Install Dependencies
cd ~/.openclaw/workspace/skills/jimeng-ai
npm install
Workflow
First Execution (New Task)
When running with a new prompt, the script will:
- Submit the task to the API
- Use
md5(提示词)as the folder name to create a directory - Save
param.json、response.jsonandtaskId.txt - Output:
"任务已提交,TaskId: xxx"
$ npx ts-node scripts/text2image.ts "一只可爱的猫咪"
任务已提交,TaskId: 1234567890
Subsequent Execution (Asynchronous Query)
Running with the same prompt will query the existing task:
- If the image already exists -> return the image path immediately
- If the task is not completed -> output:
"任务未完成,TaskId: xxx" - If the task is completed -> from
binary_data_base64decode and save the image
$ npx ts-node scripts/text2image.ts "一只可爱的猫咪"
任务未完成,TaskId: 1234567890
# 或者任务完成时:
$ npx ts-node scripts/text2image.ts "一只可爱的猫咪"
任务已完成,图片保存路径:
- ./output/<md5_hash>/1.jpg
- ./output/<md5_hash>/2.jpg
Usage
Basic Usage
npx ts-node scripts/text2image.ts "一只可爱的猫咪"
Full Parameters
npx ts-node scripts/text2image.ts "提示词" \
--version v40 \
--ratio 16:9 \
--count 2
Parameter Description
| Parameter | Description | Default Value |
|---|---|---|
prompt |
Image generation prompt (required) | - |
--version |
API version: v30, v31, v40 |
v31 |
--ratio |
Aspect ratio: 1:1, 9:16, 16:9, 3:4, 4:3, 2:3, 3:2, 1:2, 2:1 |
16:9 |
--count |
Generation count 1-4 | 1 |
--width |
Specify width (optional) | - |
--height |
Specify height (optional) | - |
--size |
Specify area (optional, e.g. 4194304 means 2048x2048) | - |
--seed |
Random seed (optional) | - |
--output |
Image output directory | ./output |
--debug |
Debug mode | false |
--no-download |
Do not download the image, only return the URL | false |
Output Format
Task Submitted (First Run)
{
"success": true,
"submitted": true,
"prompt": "一只可爱的猫咪",
"version": "v40",
"ratio": "1:1",
"count": 1,
"taskId": "1234567890",
"folder": "./output/<md5_hash>",
"message": "任务已提交,请稍后使用相同提示词查询结果"
}
Task Completed
{
"success": true,
"prompt": "一只可爱的猫咪",
"version": "v40",
"ratio": "1:1",
"count": 1,
"taskId": "1234567890",
"images": [
"./output/<md5_hash>/1.jpg",
"./output/<md5_hash>/2.jpg"
],
"outputDir": "./output/<md5_hash>"
}
Task Not Completed
{
"success": true,
"prompt": "一只可爱的猫咪",
"version": "v40",
"ratio": "1:1",
"count": 1,
"taskId": "1234567890",
"folder": "./output/<md5_hash>",
"message": "任务未完成,请稍后使用相同提示词查询结果"
}
Error Response
{
"success": false,
"error": {
"code": "MISSING_CREDENTIALS",
"message": "请设置环境变量 VOLCENGINE_AK 和 VOLCENGINE_SK"
}
}
Folder Structure
output/
└── <md5(prompt)>/ # md5哈希作为文件夹名
├── param.json # 请求参数
├── response.json # API提交响应
├── taskId.txt # 任务ID
└── 1.jpg, 2.jpg, ... # 生成的图片
Examples
Generate a landscape painting
npx ts-node scripts/text2image.ts "山水风景画,水墨风格" --version v40 --ratio 16:9
Generate a sci-fi city
npx ts-node scripts/text2image.ts "未来科幻城市,霓虹灯光,赛博朋克风格" --version v40 --ratio 16:9 --count 2
Generate with specified dimensions
npx ts-node scripts/text2image.ts "抽象艺术" --width 2048 --height 1152
Custom output directory
npx ts-node scripts/text2image.ts "一只可爱的猫咪" --output ~/Pictures/jimeng
Version Notes
- v30: Jimeng 3.0 Basic Version
- v31: Jimeng 3.1 Improved Version
- v40: Jimeng 4.0 Latest Version (Recommended)
Text-to-Video Usage
Basic Usage
npx ts-node scripts/text2video.ts "一只可爱的猫咪在草地上奔跑"
Full Parameters
npx ts-node scripts/text2video.ts "提示词" \
--ratio 9:16 \
--duration 5 \
--fps 24
Parameter Description
| Parameter | Description | Default Value |
|---|---|---|
prompt |
Video generation prompt (required) | - |
--ratio |
Aspect ratio: 16:9, 4:3, 1:1, 3:4, 9:16, 21:9 |
9:16 |
--duration |
Video duration: 5 or 10 seconds |
5 |
--fps |
Frame rate: 24 or 30 |
24 |
--output |
Video output directory | ./output |
--wait |
Wait for task completion | false |
--debug |
Debug mode | false |
--no-download |
Do not download the video, only return the URL | false |
Video output format
Task submitted
{
"success": true,
"submitted": true,
"prompt": "元宵节灯笼",
"ratio": "9:16",
"duration": 5,
"fps": 24,
"taskId": "1234567890",
"folder": "./output/video/<md5_hash>",
"message": "任务已提交,请稍后使用相同提示词查询结果"
}
Task completed
{
"success": true,
"prompt": "元宵节灯笼",
"ratio": "9:16",
"duration": 5,
"fps": 24,
"taskId": "1234567890",
"videoUrl": "https://...",
"data": {}
}
Task not completed
{
"success": true,
"pending": true,
"prompt": "元宵节灯笼",
"ratio": "9:16",
"duration": 5,
"fps": 24,
"taskId": "1234567890",
"status": "in_queue",
"message": "任务处理中,请稍后使用相同提示词查询结果"
}
Video folder structure
output/video/
└── <md5(prompt)>/ # md5哈希作为文件夹名
├── param.json # 请求参数
├── response.json # API提交响应
├── taskId.txt # 任务ID
└── video.mp4 # 生成的视频