glm-image-gen

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GLM-Image Generation Skill / GLM-Image 图片生成技能

GLM-Image 图片生成技能

Generate high-quality images from text prompts using the ZhiPu GLM-Image API.
借助智谱GLM-Image API,通过文本提示词生成高质量图片。

When to Use / 使用场景

使用场景

  • Generate images from text descriptions / 从文字描述生成图片
  • Create AI art, illustrations, or concept art / 创作 AI 艺术、插画或概念图
  • User mentions "生图", "文生图", "AI 绘画", "generate image", "text-to-image", "create image"
  • User provides a prompt and wants to see it visualized / 用户提供描述并想看到可视化效果
  • 从文字描述生成图片
  • 创作AI艺术、插画或概念图
  • 用户提及“生图”、“文生图”、“AI绘画”、“generate image”、“text-to-image”、“create image”相关需求
  • 用户提供描述并想看到可视化效果

Key Features / 核心特性

核心特性

  • High-quality generation: HD mode produces more detailed, refined images (~20s)
  • Multiple aspect ratios: Square, portrait, landscape formats supported
  • GLM-Image model: Latest model with improved understanding and quality
  • Excellent at: Scientific illustrations (科普插画), high-quality portraits (高质量人像), social media graphics (社交媒体图文), commercial posters (商业海报)
  • Watermark control: Enable/disable watermarks (requires signed disclaimer for no-watermark)
  • Content safety: Built-in content filtering for compliance
  • 高质量生成:高清模式可生成细节更丰富、质感更细腻的图片(耗时约20秒)
  • 多种宽高比:支持正方形、纵向、横向等多种画幅
  • GLM-Image模型:最新版本模型,语义理解能力和生成质量更优
  • 擅长场景:科普插画、高质量人像、社交媒体图文、商业海报
  • 水印控制:可开启/关闭水印(关闭水印需签署免责声明)
  • 内容安全:内置内容过滤机制,符合合规要求

Resource Links / 资源链接

资源链接

Prerequisites / 前置条件

前置条件

API Key Setup / API Key 配置(Required / 必需)

API Key 配置(必需)

脚本通过
ZHIPU_API_KEY
环境变量获取密钥,可与其他智谱技能复用同一个 key。 This script reads the key from the
ZHIPU_API_KEY
environment variable. Reusing the same key across Zhipu skills is optional.
Get Key / 获取 Key: Visit 智谱开放平台 API Keys to create or copy your key.
Setup options / 配置方式(任选一种):
  1. Global config (recommended) / 全局配置(推荐): Set once in
    openclaw.json
    under
    env.vars
    , all Zhipu skills will share it:
    json
    {
      "env": {
        "vars": {
          "ZHIPU_API_KEY": "你的密钥"
        }
      }
    }
  2. Skill-level config / Skill 级别配置: Set for this skill only in
    openclaw.json
    :
    json
    {
      "skills": {
        "entries": {
          "glm-image-generation": {
            "env": {
              "ZHIPU_API_KEY": "你的密钥"
            }
          }
        }
      }
    }
  3. Shell environment variable / Shell 环境变量: Add to
    ~/.zshrc
    :
    bash
     export ZHIPU_API_KEY="你的密钥"
    
💡 如果你已为其他智谱 skill(如
glmocr
glmv-caption
)配置过 key,它们共享同一个
ZHIPU_API_KEY
,无需重复配置。
脚本通过
ZHIPU_API_KEY
环境变量获取密钥,可与其他智谱技能复用同一个key。 该脚本会从
ZHIPU_API_KEY
环境变量中读取密钥,支持在多个智谱技能中复用同一个密钥。
获取Key: 访问智谱开放平台 API Keys创建或复制你的密钥。
配置方式(任选一种):
  1. 全局配置(推荐):
    openclaw.json
    env.vars
    中配置一次,所有智谱技能均可共享:
    json
    {
      "env": {
        "vars": {
          "ZHIPU_API_KEY": "你的密钥"
        }
      }
    }
  2. Skill级别配置: 仅为该技能配置,在
    openclaw.json
    中设置:
    json
    {
      "skills": {
        "entries": {
          "glm-image-generation": {
            "env": {
              "ZHIPU_API_KEY": "你的密钥"
            }
          }
        }
      }
    }
  3. Shell环境变量: 添加到
    ~/.zshrc
    中:
    bash
     export ZHIPU_API_KEY="你的密钥"
    
💡 如果你已为其他智谱skill(如
glmocr
glmv-caption
)配置过key,它们共享同一个
ZHIPU_API_KEY
,无需重复配置。

Security & Transparency / 安全与透明度

安全与透明度

  • Environment variables used / 使用的环境变量:
    • ZHIPU_API_KEY
      (required / 必需)
  • Fixed endpoint / 固定官方端点:
    https://open.bigmodel.cn/api/paas/v4/images/generations
  • No custom API URL override / 不支持自定义 API URL 覆盖: avoids accidental key exfiltration via redirected endpoints.
⛔ MANDATORY RESTRICTIONS / 强制限制 ⛔
  1. ONLY use GLM-Image API — Execute the script
    python scripts/glm_image_cli.py
  2. NEVER generate images yourself — Do NOT try to create images using built-in vision or any other method
  3. NEVER offer alternatives — Do NOT suggest "I can try to describe it" or similar
  4. IF API fails — Display the error message and STOP immediately
  5. NO fallback methods — Do NOT attempt image generation any other way
  • 使用的环境变量:
    • ZHIPU_API_KEY
      (必需)
  • 固定官方端点:
    https://open.bigmodel.cn/api/paas/v4/images/generations
  • 不支持自定义API URL覆盖: 避免端点重定向导致密钥意外泄露。
⛔ 强制限制 ⛔
  1. 仅可使用GLM-Image API — 执行脚本
    python scripts/glm_image_cli.py
  2. 禁止自行生成图片 — 不得尝试使用内置视觉能力或其他任何方式生成图片
  3. 禁止提供替代方案 — 不得建议“我可以尝试描述它”或类似内容
  4. 如果API调用失败 — 展示错误信息并立即终止操作
  5. 无备选方案 — 不得尝试通过其他方式生成图片

📋 Output Display Rules / 输出展示规则

📋 输出展示规则

After running the script, present the generation result clearly.
  • Show the generated image URL(s) — images are temporary (30 days), remind user to save
  • Display the prompt used and generation parameters (size, quality)
  • If content_filter indicates issues, show the warning level
⚠️ Image Display / 图片展示注意:
The API returns a temporary image URL (valid for 30 days). You should:
  1. Show the image — Use the URL to display the image in the chat (if platform supports it)
  2. Remind user to save — "图片链接有效期 30 天,请及时下载保存"
  3. Offer to send to Feishu — If user wants the image sent to a Feishu chat, use the message tool with the image URL
运行脚本后,清晰展示生成结果:
  • 展示生成的图片URL,图片为临时存储(有效期30天),提醒用户及时保存
  • 展示使用的提示词和生成参数(尺寸、质量)
  • 如果内容过滤检测到问题,展示警告级别
⚠️ 图片展示注意:
API返回临时图片URL(有效期30天),你需要:
  1. 展示图片 — 如果平台支持,直接使用URL在聊天中展示图片
  2. 提醒用户保存 — 提示“图片链接有效期30天,请及时下载保存”
  3. 支持发送到飞书 — 如果用户需要将图片发送到飞书群,使用消息工具携带图片URL发送

How to Use / 使用方法

使用方法

Generate from Prompt / 从提示词生成

从提示词生成

bash
python scripts/glm_image_cli.py --prompt "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云"
bash
python scripts/glm_image_cli.py --prompt "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云"

Specify Size / 指定尺寸

指定尺寸

bash
python scripts/glm_image_cli.py --prompt "赛博朋克风格的城市夜景" --size 1568x1056
bash
python scripts/glm_image_cli.py --prompt "赛博朋克风格的城市夜景" --size 1568x1056

HD Quality (default for glm-image) / 高清质量(glm-image 默认)

高清质量(glm-image默认)

bash
python scripts/glm_image_cli.py --prompt "中国山水画风格,远山近水,云雾缭绕" --quality hd
bash
python scripts/glm_image_cli.py --prompt "中国山水画风格,远山近水,云雾缭绕" --quality hd

Disable Watermark (requires signed disclaimer) / 关闭水印(需签署免责声明)

关闭水印(需签署免责声明)

bash
python scripts/glm_image_cli.py --prompt "商业设计素材" --no-watermark
bash
python scripts/glm_image_cli.py --prompt "商业设计素材" --no-watermark

Save Image to Local File / 保存图片到本地

保存图片到本地

bash
python scripts/glm_image_cli.py --prompt "中国水墨画风格" --save image.png
python scripts/glm_image_cli.py --prompt "赛博朋克城市" --size 1728x960 --save ~/Pictures/cyberpunk.png
bash
python scripts/glm_image_cli.py --prompt "中国水墨画风格" --save image.png
python scripts/glm_image_cli.py --prompt "赛博朋克城市" --size 1728x960 --save ~/Pictures/cyberpunk.png

Specify User ID (for content moderation) / 指定用户 ID(用于内容审核)

指定用户ID(用于内容审核)

bash
python scripts/glm_image_cli.py --prompt "..." --user-id "user_12345"
bash
python scripts/glm_image_cli.py --prompt "..." --user-id "user_12345"

Specify Model / 指定模型

指定模型

bash
python scripts/glm_image_cli.py --prompt "..." --model glm-image
python scripts/glm_image_cli.py --prompt "..." --model cogview-4
bash
python scripts/glm_image_cli.py --prompt "..." --model glm-image
python scripts/glm_image_cli.py --prompt "..." --model cogview-4

CLI Reference / CLI 参数

CLI参数参考

python {baseDir}/scripts/glm_image_cli.py --prompt TEXT [--model MODEL] [--size SIZE] [--quality QUALITY] [--no-watermark] [--user-id ID] [--save FILE]
ParameterRequiredDescription
--prompt
,
-p
YesText description of the desired image / 图片的文本描述
--model
,
-m
NoModel: glm-image (default), cogview-4, cogview-3-flash / 模型
--size
,
-s
NoImage size (default: 1280x1280) / 图片尺寸
--quality
,
-q
NoQuality: hd (default) or standard / 质量
--no-watermark
NoDisable watermark (requires signed disclaimer) / 关闭水印
--user-id
NoEnd-user ID for content moderation (6-128 chars) / 终端用户 ID
--save
NoSave generated image to local file / 保存生成的图片到本地文件
python {baseDir}/scripts/glm_image_cli.py --prompt TEXT [--model MODEL] [--size SIZE] [--quality QUALITY] [--no-watermark] [--user-id ID] [--save FILE]
参数必填说明
--prompt
,
-p
想要生成的图片的文本描述
--model
,
-m
模型:glm-image(默认)、cogview-4、cogview-3-flash
--size
,
-s
图片尺寸(默认:1280x1280)
--quality
,
-q
质量:hd(默认)或standard
--no-watermark
关闭水印(需签署免责声明)
--user-id
用于内容审核的终端用户ID(6-128个字符)
--save
将生成的图片保存到本地文件

Supported Sizes / 支持的尺寸

支持的尺寸

GLM-Image recommended sizes:
SizeAspect RatioUse Case
1280x12801:1Square (default)
1568×10563:2Landscape / 横向
1056×15682:3Portrait / 纵向
1472×1088~4:3Wide landscape
1088×1472~3:4Tall portrait
1728×96016:9Ultra-wide landscape
960×17289:16Ultra-tall portrait
Custom sizes / 自定义尺寸:
  • Width and height: 1024px - 2048px
  • Both dimensions must be multiples of 32 / 长宽均需为 32 的整数倍
  • Maximum total pixels: 2^22 (4,194,304 px) / 最大像素数不超过 2^22
GLM-Image推荐尺寸:
尺寸宽高比适用场景
1280x12801:1正方形(默认)
1568×10563:2横向
1056×15682:3纵向
1472×1088~4:3宽幅横向
1088×1472~3:4长款纵向
1728×96016:9超宽横向
960×17289:16超长纵向
自定义尺寸规则:
  • 宽度和高度范围:1024px - 2048px
  • 长宽均需为32的整数倍
  • 最大像素数不超过2^22(4,194,304 px)

Response Format / 响应格式

响应格式

Official API Response:
json
{
  "created": 123,
  "data": [
    {
      "url": "<string>"
    }
  ],
  "content_filter": [
    {
      "role": "assistant",
      "level": 1
    }
  ]
}
CLI Output Format:
json
{
  "ok": true,
  "model": "glm-image",
  "image_url": "https://open.bigmodel.cn/.../generated_image.png",
  "prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云",
  "size": "1280x1280",
  "quality": "hd",
  "created": 1710835200,
  "content_filter": [
    {
      "role": "assistant",
      "level": 3
    }
  ],
  "saved_file": "/Users/xxx/image.png",
  "error": null
}
Key fields:
  • ok
    — whether generation succeeded
  • model
    — model used for generation
  • image_url
    — extracted from
    data[0].url
    , temporary URL (valid 30 days)
  • prompt
    — the text prompt used
  • size
    — generated image dimensions
  • quality
    — hd or standard
  • created
    — Unix timestamp when request was created
  • content_filter
    — content safety analysis array (may be empty)
    • role
      : where the issue was detected (user/assistant/history)
    • level
      : severity 0-3 (0 = most severe, 3 = minor)
  • saved_file
    — absolute path to saved local file (if
    --save
    was used)
  • error
    — error details on failure
官方API响应:
json
{
  "created": 123,
  "data": [
    {
      "url": "<string>"
    }
  ],
  "content_filter": [
    {
      "role": "assistant",
      "level": 1
    }
  ]
}
CLI输出格式:
json
{
  "ok": true,
  "model": "glm-image",
  "image_url": "https://open.bigmodel.cn/.../generated_image.png",
  "prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云",
  "size": "1280x1280",
  "quality": "hd",
  "created": 1710835200,
  "content_filter": [
    {
      "role": "assistant",
      "level": 3
    }
  ],
  "saved_file": "/Users/xxx/image.png",
  "error": null
}
核心字段说明:
  • ok
    — 生成是否成功
  • model
    — 生成使用的模型
  • image_url
    — 从
    data[0].url
    提取的临时图片URL(有效期30天)
  • prompt
    — 使用的文本提示词
  • size
    — 生成的图片尺寸
  • quality
    — 高清或标准质量
  • created
    — 请求创建的Unix时间戳
  • content_filter
    — 内容安全分析数组(可能为空)
    • role
      : 问题检测位置(user/assistant/history)
    • level
      : 严重程度0-3(0=最严重,3=轻微)
  • saved_file
    — 本地保存文件的绝对路径(如果使用了
    --save
    参数)
  • error
    — 失败时的错误详情

Content Safety / 内容安全

内容安全

The API includes content filtering. If issues are detected,
content_filter
will contain entries with:
  • role
    : where the issue was detected (user/assistant/history)
  • level
    : severity 0-3 (0 = most severe, 3 = minor)
If level 0-1 detected: Generation will fail, show error to user. If level 2-3 detected: Generation may succeed, but warn user about potential issues.
API内置内容过滤机制,如果检测到问题,
content_filter
会包含以下字段的条目:
  • role
    : 问题检测位置(user/assistant/history)
  • level
    : 严重程度0-3(0=最严重,3=轻微)
如果检测到级别0-1: 生成会失败,向用户展示错误。 如果检测到级别2-3: 生成可能成功,但需要警告用户存在潜在问题。

Error Handling / 错误处理

错误处理

API key not configured:
json
{
  "ok": false,
  "error": {
    "code": "MISSING_API_KEY",
    "message": "ZHIPU_API_KEY not configured. Get your API key at: https://bigmodel.cn/usercenter/proj-mgmt/apikeys"
  }
}
→ Show exact error to user, guide them to configure
Authentication failed (401/403):
json
{
  "ok": false,
  "error": {
    "code": "authentication_error",
    "message": "令牌已过期或验证不正确",
    "status": 401
  }
}
→ API key invalid/expired → reconfigure
Rate limit (429):
json
{
  "ok": false,
  "error": {
    "code": "rate_limit_exceeded",
    "message": "API rate limit exceeded. Please try again later.",
    "status": 429
  }
}
→ Quota exhausted → inform user to wait or check quota
Content filter violation:
json
{
  "ok": false,
  "error": {
    "code": "content_filter_violation",
    "message": "Content safety check failed",
    "status": 400
  }
}
→ Explain that the prompt may contain inappropriate content
Invalid size:
json
{
  "ok": false,
  "error": {
    "code": "INVALID_SIZE",
    "message": "Invalid size: 512x512 for model glm-image. Must be multiple of 32, 1024-2048px, max 2^22 pixels"
  }
}
→ Guide user to use valid size from the supported list
Download failed:
json
{
  "ok": false,
  "error": {
    "code": "DOWNLOAD_FAILED",
    "message": "Failed to download image to image.png"
  }
}
→ Check file path permissions and disk space
Network error:
json
{
  "ok": false,
  "error": {
    "code": "NETWORK_ERROR",
    "message": "Network error: [Errno 8] nodename nor servname provided, or not known"
  }
}
→ Check internet connection
API key未配置:
json
{
  "ok": false,
  "error": {
    "code": "MISSING_API_KEY",
    "message": "ZHIPU_API_KEY not configured. Get your API key at: https://bigmodel.cn/usercenter/proj-mgmt/apikeys"
  }
}
→ 向用户展示完整错误,引导其完成配置
认证失败(401/403):
json
{
  "ok": false,
  "error": {
    "code": "authentication_error",
    "message": "令牌已过期或验证不正确",
    "status": 401
  }
}
→ API key无效/已过期 → 引导用户重新配置
速率限制(429):
json
{
  "ok": false,
  "error": {
    "code": "rate_limit_exceeded",
    "message": "API rate limit exceeded. Please try again later.",
    "status": 429
  }
}
→ 配额耗尽 → 告知用户稍后重试或检查配额
内容过滤违规:
json
{
  "ok": false,
  "error": {
    "code": "content_filter_violation",
    "message": "Content safety check failed",
    "status": 400
  }
}
→ 说明提示词可能包含不当内容
无效尺寸:
json
{
  "ok": false,
  "error": {
    "code": "INVALID_SIZE",
    "message": "Invalid size: 512x512 for model glm-image. Must be multiple of 32, 1024-2048px, max 2^22 pixels"
  }
}
→ 引导用户使用支持列表中的有效尺寸
下载失败:
json
{
  "ok": false,
  "error": {
    "code": "DOWNLOAD_FAILED",
    "message": "Failed to download image to image.png"
  }
}
→ 检查文件路径权限和磁盘空间
网络错误:
json
{
  "ok": false,
  "error": {
    "code": "NETWORK_ERROR",
    "message": "Network error: [Errno 8] nodename nor servname provided, or not known"
  }
}
→ 检查网络连接

Prompt Tips / 提示词技巧

提示词技巧

Good prompts:
  • Specific details: "一只橘色的英国短毛猫,绿色眼睛,坐在木质窗台上"
  • Style keywords: "赛博朋克风格", "中国水墨画", "油画质感", "3D 渲染"
  • Lighting: "阳光明媚", "柔和的逆光", "电影感灯光"
  • Composition: "特写镜头", "广角视角", "俯视角度"
Avoid:
  • Vague descriptions: "好看的图片"
  • Contradictory elements: "白天和夜晚同时"
  • Too many subjects: Keep focus on 1-2 main elements
优质提示词特征:
  • 具体细节:如“一只橘色的英国短毛猫,绿色眼睛,坐在木质窗台上”
  • 风格关键词:如“赛博朋克风格”、“中国水墨画”、“油画质感”、“3D渲染”
  • 光线描述:如“阳光明媚”、“柔和的逆光”、“电影感灯光”
  • 构图说明:如“特写镜头”、“广角视角”、“俯视角度”
避免以下问题:
  • 模糊描述:如“好看的图片”
  • 矛盾元素:如“白天和夜晚同时出现”
  • 主体过多:尽量聚焦1-2个核心元素