generating-images

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Generating Images (OpenAI gpt-image-2)

生成图像(OpenAI gpt-image-2)

Use this skill any time the user asks to generate or edit an image. It wraps OpenAI's
gpt-image-2
model via a Python script, supports both text-only prompts and one-or-more reference images, and writes the resulting PNG/JPEG/WebP to disk.
每当用户要求生成或编辑图像时,均可使用此技能。它通过Python脚本封装了OpenAI的
gpt-image-2
模型,支持纯文本提示词和一张或多张参考图像,并将生成的PNG/JPEG/WebP格式图像写入磁盘。

Hard rules (do not violate)

硬性规则(不得违反)

  1. Always use
    gpt-image-2
    .
    Never fall back to
    gpt-image-1
    ,
    dall-e-3
    , or any other model. The script has no
    --model
    flag for this reason.
  2. Fail fast on any error. Do not retry, do not swap models, do not patch around missing credentials, do not silently degrade quality. If the script exits non-zero, surface the error to the user verbatim and stop.
  3. Do not "fix" a missing
    OPENAI_API_KEY
    by reading from
    .env
    files, 1Password, etc. unless the user explicitly tells you to. If the env var is missing, ask the user how they want to provide it (or to
    export
    it) and then stop.
  1. 始终使用
    gpt-image-2
    。绝不降级使用
    gpt-image-1
    dall-e-3
    或其他任何模型。为此,脚本未设置
    --model
    参数。
  2. 遇到错误立即终止。不要重试,不要切换模型,不要绕过缺失的凭证问题,不要悄悄降低质量。如果脚本非零退出,直接将错误原封不动告知用户并停止操作。
  3. 不要主动修复缺失的
    OPENAI_API_KEY
    ,除非用户明确指示,否则不要从.env文件、1Password等位置读取密钥。如果环境变量缺失,请询问用户提供方式(或让用户执行
    export
    命令),然后停止操作。

When to use

使用场景

  • User asks for a generated image: icon, logo, illustration, mockup, OG image, blog hero, marketing asset, concept art, diagram-style image, etc.
  • User provides one or more images and asks to edit, restyle, combine, or use them as references.
  • User asks to remove/replace part of an image (use
    --mask
    ).
Do not use this skill for:
  • Charts/plots/data viz (generate via code instead).
  • Sourcing existing photos (use a stock photo skill if available).
  • Screenshots of the user's app (use a screenshot skill if available).
  • 用户要求生成图像:图标、Logo、插画、模型图、OG图像、博客首图、营销素材、概念艺术、图表风格图像等。
  • 用户提供一张或多张图像,要求编辑、重新设计风格、组合或作为参考使用。
  • 用户要求移除/替换图像的部分内容(使用
    --mask
    参数)。
请勿将此技能用于:
  • 图表/绘图/数据可视化(应通过代码生成)。
  • 获取现有照片(如有可用的图库照片技能,请使用该技能)。
  • 截取用户应用的屏幕截图(如有可用的截图技能,请使用该技能)。

Prerequisites

前置条件

1. OpenAI API key

1. OpenAI API密钥

You need an
OPENAI_API_KEY
exported in your environment. Get one at platform.openai.com/api-keys.
The skill ships with a
.env.example
next to this
SKILL.md
. Copy it and fill in your key:
bash
cp .env.example .env
您需要在环境变量中导出
OPENAI_API_KEY
。可前往platform.openai.com/api-keys获取。
本技能在
SKILL.md
旁提供了
.env.example
文件。复制该文件并填入您的密钥:
bash
cp .env.example .env

then edit .env and put your real key in

编辑.env文件并填入真实密钥


Then export it before running the script:

```bash
set -a && source .env && set +a
Or just export it directly in your shell:
bash
export OPENAI_API_KEY="sk-..."
If
OPENAI_API_KEY
is not set, the script exits with code 2 immediately. Do not try to read it from anywhere else without the user's explicit permission.

运行脚本前导出密钥:

```bash
set -a && source .env && set +a
或者直接在shell中导出:
bash
export OPENAI_API_KEY="sk-..."
如果未设置
OPENAI_API_KEY
,脚本会立即以代码2退出。未经用户明确许可,请勿尝试从其他位置读取密钥。

2. Org verification

2. 组织验证

Your OpenAI org must be verified for
gpt-image-2
at platform.openai.com/settings/organization/general. If you see a 403 mentioning "organization must be verified", surface it and stop — do not switch models.
您的OpenAI组织必须在platform.openai.com/settings/organization/general完成
gpt-image-2
的验证。如果收到403错误提示“organization must be verified”,请告知用户并停止操作——不要切换模型。

3. Python dependency

3. Python依赖

bash
pip install --upgrade openai
bash
pip install --upgrade openai

Script location

脚本位置

The Python script lives next to this
SKILL.md
at
scripts/generate_image.py
. When this skill is installed at
~/.cursor/skills/generating-images/
, the script will be at
~/.cursor/skills/generating-images/scripts/generate_image.py
.
It prints the absolute path(s) of the written image(s) to stdout. Errors go to stderr with a non-zero exit code, and the script exits immediately on the first error.
Python脚本位于
SKILL.md
旁的
scripts/generate_image.py
。当本技能安装在
~/.cursor/skills/generating-images/
时,脚本路径为
~/.cursor/skills/generating-images/scripts/generate_image.py
脚本会将生成图像的绝对路径打印到标准输出。错误信息会输出到标准错误流并伴随非零退出码,且脚本会在首次出错时立即退出。

How to invoke

调用方式

Always run via the Shell tool. Pick a sensible output path inside the user's current workspace (e.g.
./public/generated/<slug>.png
for web projects, or
./<slug>.png
otherwise).
始终通过Shell工具运行脚本。在用户当前工作区中选择合理的输出路径(例如,Web项目使用
./public/generated/<slug>.png
,其他项目使用
./<slug>.png
)。

1. Text-to-image

1. 文本转图像

bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "Minimal flat-vector app icon for a note-taking app, indigo gradient, rounded square, soft shadow" \
  --size 1024x1024 \
  --quality high \
  --out ./icon.png
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "极简扁平化矢量笔记应用图标,靛蓝渐变,圆角方形,柔和阴影" \
  --size 1024x1024 \
  --quality high \
  --out ./icon.png

2. Image-to-image (one reference)

2. 图像转图像(单张参考图)

bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "Restyle this photo as a watercolor painting with warm tones" \
  --image ./photo.jpg \
  --out ./photo-watercolor.png
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "将这张照片重新设计为暖色调水彩画风格" \
  --image ./photo.jpg \
  --out ./photo-watercolor.png

3. Multiple reference images

3. 多张参考图像

bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "Photorealistic flat-lay product shot combining all of these items on a white background" \
  --image ./a.png --image ./b.png --image ./c.png \
  --out ./flatlay.png
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "将所有物品组合在白色背景上的写实平铺产品照片" \
  --image ./a.png --image ./b.png --image ./c.png \
  --out ./flatlay.png

4. Masked edit (inpainting)

4. 蒙版编辑(图像修复)

The mask must be the same size and format as the first input image, with an alpha channel marking the editable region.
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "Replace the sky with a vivid sunset" \
  --image ./scene.png --mask ./sky-mask.png \
  --out ./scene-sunset.png
蒙版必须与第一张输入图像尺寸和格式相同,且带有标记可编辑区域的Alpha通道。
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --prompt "将天空替换为绚烂的日落" \
  --image ./scene.png --mask ./sky-mask.png \
  --out ./scene-sunset.png

5. Batch / parallel mode (many distinct images at once)

5. 批量/并行模式(一次性生成多张不同图像)

When you need to generate multiple different images in one go (e.g. a set of blog heroes, several icon variations with different prompts, OG images for many pages), use
--batch
instead of running the script N times. It runs all jobs in parallel from a single Python process — much faster than serial calls and avoids repeated SDK startup cost.
Write a JSON file describing every job, then call the script once:
bash
cat > /tmp/img-jobs.json <<'EOF'
[
  {
    "prompt": "Minimal flat-vector app icon for a note-taking app, indigo gradient, rounded square",
    "out": "./public/icons/notes.png",
    "size": "1024x1024",
    "quality": "high"
  },
  {
    "prompt": "Photoreal blog hero: a cozy library with warm afternoon light, 5:3 ratio",
    "out": "./public/static/blog/library.png",
    "size": "1600x960",
    "quality": "medium"
  },
  {
    "prompt": "Restyle this product photo as a watercolor painting with warm tones",
    "image": ["./public/products/mug.jpg"],
    "out": "./public/products/mug-watercolor.png"
  }
]
EOF

python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --batch /tmp/img-jobs.json --concurrency 5
Each job object accepts the same fields as the CLI flags:
prompt
(required),
out
,
size
,
quality
,
format
,
n
,
image
(string or array of strings),
mask
. Defaults match the single-shot CLI.
Behavior:
  • All jobs run concurrently up to
    --concurrency
    (default 4). A reasonable range is 3–8; OpenAI rate-limits per org so don't go too wild.
  • Each successfully written image's absolute path is printed to stdout as soon as that job finishes, one per line.
  • If any job fails, its error is printed to stderr (
    ERROR: job <i> failed: ...
    ) and the script exits with code 1 after the remaining jobs finish. Other jobs are not cancelled — partial output is fine and you can retry only the failed ones.
  • --batch
    is mutually exclusive with
    --prompt
    /
    --image
    /
    --mask
    .
When to prefer
--batch
over parallel Shell calls:
any time you're generating ≥2 distinct images in the same turn. Don't fire multiple parallel Shell invocations of this script — use one batch call instead.
Don't confuse with
--n
.
--n
produces multiple variations of the same prompt in a single API call (cheaper, but all the same idea).
--batch
runs different prompts in parallel. They can be combined: a batch job can set
"n": 4
to get 4 variations of that one prompt.
当您需要一次性生成多张不同图像时(例如,一组博客首图、多个不同提示词的图标变体、多个页面的OG图像),请使用
--batch
参数,而非重复运行脚本N次。它会在单个Python进程中并行运行所有任务——比串行调用快得多,且避免重复的SDK启动开销。
编写描述所有任务的JSON文件,然后调用一次脚本:
bash
cat > /tmp/img-jobs.json <<'EOF'
[
  {
    "prompt": "极简扁平化矢量笔记应用图标,靛蓝渐变,圆角方形",
    "out": "./public/icons/notes.png",
    "size": "1024x1024",
    "quality": "high"
  },
  {
    "prompt": "写实风格博客首图:温暖午后阳光下的舒适图书馆,5:3比例",
    "out": "./public/static/blog/library.png",
    "size": "1600x960",
    "quality": "medium"
  },
  {
    "prompt": "将这张产品照片重新设计为暖色调水彩画风格",
    "image": ["./public/products/mug.jpg"],
    "out": "./public/products/mug-watercolor.png"
  }
]
EOF

python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
  --batch /tmp/img-jobs.json --concurrency 5
每个任务对象接受与CLI参数相同的字段:
prompt
(必填)、
out
size
quality
format
n
image
(字符串或字符串数组)、
mask
。默认值与单次调用CLI的设置一致。
行为说明:
  • 所有任务会并行运行,最大并发数由
    --concurrency
    设置(默认4)。合理范围为3–8;OpenAI会按组织进行速率限制,请勿设置过高。
  • 每个成功写入的图像绝对路径会在任务完成后立即打印到标准输出,每行一个路径。
  • 如果任何任务失败,错误信息会输出到标准错误流(
    ERROR: job <i> failed: ...
    ),脚本会在剩余任务完成后以代码1退出。其他任务不会被取消——允许部分输出,您可以仅重试失败的任务。
  • --batch
    --prompt
    /
    --image
    /
    --mask
    互斥。
何时优先使用
--batch
而非并行Shell调用:
当您需要在同一轮操作中生成≥2张不同图像时。请勿触发多个并行的脚本Shell调用——请改用一次批量调用。
不要与
--n
混淆。
--n
会在单次API调用中生成同一提示词的多个变体(成本更低,但都是相同主题)。
--batch
会并行运行不同的提示词。两者可以结合使用:批量任务中设置
"n": 4
可生成该提示词的4个变体。

Flags reference

参数参考

FlagDefaultNotes
--prompt
required*Required unless
--batch
is used. Always include, even when editing.
--image
nonePass multiple times for multiple references. Triggers
images.edit
.
--mask
noneOptional inpainting mask (PNG with alpha).
--out
./image.png
Output path; index suffix added when
--n > 1
.
--size
auto
1024x1024
,
1536x1024
,
1024x1536
,
2048x2048
,
3840x2160
, etc. Edges must be multiples of 16, max 3840px, ratio ≤ 3:1.
--quality
auto
low
(fast drafts),
medium
,
high
(final assets).
--format
png
png
,
jpeg
,
webp
.
--n
1
Variations of the SAME prompt in one call.
--batch
nonePath to JSON array of job objects; runs them in parallel.
--concurrency
4
Max parallel workers in
--batch
mode.
There is intentionally no
--model
flag
. The model is hardcoded to
gpt-image-2
.
参数默认值说明
--prompt
必填*除非使用
--batch
,否则为必填项。即使是编辑图像,也必须填写。
--image
可多次传递以使用多张参考图。会触发
images.edit
接口。
--mask
可选的图像修复蒙版(带Alpha通道的PNG)。
--out
./image.png
输出路径;当
--n > 1
时会添加索引后缀。
--size
auto
可选值包括
1024x1024
1536x1024
1024x1536
2048x2048
3840x2160
等。边长必须为16的倍数,最大3840px,比例≤3:1。
--quality
auto
可选值:
low
(快速草稿)、
medium
high
(最终素材)。
--format
png
可选值:
png
jpeg
webp
--n
1
同一提示词的变体数量,单次调用生成。
--batch
JSON格式任务数组的路径;并行运行这些任务。
--concurrency
4
--batch
模式下的最大并行工作线程数。
脚本故意未设置
--model
参数
,模型已硬编码为
gpt-image-2

Sizing guidance

尺寸指南

  • App icons / square thumbnails →
    1024x1024
  • Landing-page heroes / OG images →
    1536x1024
  • Blog hero (5:3) →
    1600x960
    (both edges multiples of 16, ratio = 5:3)
  • Mobile / portrait illustrations →
    1024x1536
  • Marketing posters / 4K assets →
    3840x2160
  • 应用图标/方形缩略图 →
    1024x1024
  • 落地页首图/OG图像 →
    1536x1024
  • 博客首图(5:3比例) →
    1600x960
    (两边均为16的倍数,比例=5:3)
  • 移动端/竖版插画 →
    1024x1536
  • 营销海报/4K素材 →
    3840x2160

Quality guidance

质量指南

  • low
    for quick exploration / drafts (cheapest, fastest).
  • medium
    is a good default.
  • high
    only for final, ship-ready assets — significantly more expensive and can take up to ~2 minutes.
If the user just says "generate an image" with no signal of finality, default to
--quality medium
.
  • low
    用于快速探索/草稿(成本最低,速度最快)。
  • medium
    是不错的默认选择。
  • high
    仅用于最终、可发布的素材——成本显著更高,生成时间可达约2分钟。
如果用户仅说“生成一张图像”且未明确要求最终版本,默认使用
--quality medium

Prompt-writing tips

提示词编写技巧

For best results, include in the prompt:
  • Subject (what is in the image)
  • Style (flat vector, watercolor, photoreal, isometric, line drawing, 3D render…)
  • Composition / camera (close-up, top-down, wide shot)
  • Color palette / mood
  • Background (white, gradient, scene — note:
    gpt-image-2
    does not support transparent backgrounds)
  • Any text that must appear, in quotes (
    gpt-image-2
    renders text well)
If the user gives a vague prompt, expand it with sensible defaults rather than asking back, unless the request is genuinely ambiguous.
为获得最佳效果,提示词应包含:
  • 主体(图像中的内容)
  • 风格(扁平化矢量、水彩、写实、等距视角、线稿、3D渲染等)
  • 构图/视角(特写、俯视、广角)
  • 调色板/氛围
  • 背景(白色、渐变、场景——注意:
    gpt-image-2
    不支持透明背景)
  • 必须出现的文字(用引号括起来,
    gpt-image-2
    能很好地渲染文字)
如果用户给出模糊的提示词,请补充合理的默认值,而非反问用户,除非请求确实存在歧义。

After generating

生成后操作

  1. Print the output path back to the user.
  2. Do not embed the image in markdown — Cursor displays generated files automatically when they are written into the workspace.
  3. If the result is meant for a website/app, consider also running it through an optimizer (e.g.
    pngquant
    ,
    cwebp
    ) when file size matters.
  1. 将输出路径告知用户。
  2. 不要在Markdown中嵌入图像——当图像写入工作区后,Cursor会自动显示。
  3. 如果生成的图像用于网站/应用,在文件大小重要的情况下,可考虑使用优化工具(如
    pngquant
    cwebp
    )进行处理。

Gather context BEFORE generating

生成前先收集上下文

Unless the user has spelled out exactly what they want (subject, style, palette, size, destination), do a quick context-gathering pass first. The goal is for the generated image to feel like it belongs where it's going, not like a random asset dropped into the project. Skipping this step is the #1 way this skill produces off-brand results.
Things to look at, in roughly this order:
  1. Sibling images at the destination. If the image will live in
    public/static/blog/
    ,
    public/static/marketing/
    ,
    assets/
    , etc., open one or two existing images in that folder with the Read tool. Match their:
    • Illustration style (3D cartoon, flat vector, photoreal, line art, isometric…)
    • Color palette and lighting
    • Subject conventions (e.g. "always features the product mascot", "always a metaphor, never literal screenshots", etc.)
    • Aspect ratio and resolution
  2. The surface that will display it. Read the relevant file:
    • Blog post → read the MDX/Markdown (title, tags, opening paragraphs, key metaphors).
    • Landing page section → read the component, headline, and surrounding copy.
    • README → read the top of the README.
    • Component → read the component to understand what it represents.
    Pull the image's meaning from the actual content, not just the filename.
  3. Brand / design tokens. If the project has a clearly defined palette, logo, or mascot, mirror them. Quick places to check:
    • tailwind.config.*
      for brand colors
    • globals.css
      / theme files for CSS variables
    • public/
      for logos / mascot assets
    • Any existing OG images or marketing assets
  4. Aspect ratio / size. Pick
    --size
    based on the surface: blog hero, OG image, square avatar, mobile portrait, etc. Match what's already there.
Then write the prompt incorporating what you learned: subject pulled from the content, style + palette pulled from sibling assets and brand tokens, composition matched to the surface.
If the user did give explicit direction (style, colors, exact subject), honor it and skip context-gathering. If they gave partial direction, gather context for the parts they left open.
Don't ask the user clarifying questions for things you can reasonably infer from the codebase — infer first, ask only when something is genuinely ambiguous (e.g. two equally valid styles already exist in the project).
除非用户明确说明所有需求(主体、风格、调色板、尺寸、使用场景),否则应先快速收集上下文信息。目标是让生成的图像适配使用场景,而非像随机素材一样插入项目。跳过此步骤是本技能生成不符合品牌风格内容的最主要原因。
需查看的内容大致顺序如下:
  1. 目标位置的同类图像。如果图像将存放在
    public/static/blog/
    public/static/marketing/
    assets/
    等目录,请使用读取工具打开该目录中的1-2张现有图像,匹配以下内容:
    • 插画风格(3D卡通、扁平化矢量、写实、线稿、等距视角等)
    • 调色板和光影
    • 主体惯例(例如“总是包含产品吉祥物”、“总是使用隐喻,从不使用文字截图”等)
    • 宽高比和分辨率
  2. 展示图像的载体。读取相关文件:
    • 博客文章 → 读取MDX/Markdown文件(标题、标签、开头段落、核心隐喻)。
    • 落地页板块 → 读取组件、标题和周围文案。
    • README → 读取README的开头部分。
    • 组件 → 读取组件以了解其代表的内容。
    从实际内容中提取图像的意义,而非仅依赖文件名。
  3. 品牌/设计规范。如果项目有明确的调色板、Logo或吉祥物,请予以匹配。快速检查位置:
    • tailwind.config.*
      中的品牌颜色
    • globals.css
      /主题文件中的CSS变量
    • public/
      目录中的Logo/吉祥物素材
    • 任何现有的OG图像或营销素材
  4. 宽高比/尺寸。根据展示载体选择
    --size
    :博客首图、OG图像、方形头像、移动端竖版等。匹配现有内容的设置。
然后编写包含以上信息的提示词:从内容中提取主体,从同类素材和品牌规范中提取风格+调色板,根据载体匹配构图。
如果用户已给出明确指示(风格、颜色、具体主体),请遵循指示并跳过上下文收集。如果用户给出部分指示,请为未明确的部分收集上下文。
对于可从代码库中合理推断的内容,不要向用户询问——先自行推断,仅在确实存在歧义时(例如项目中存在两种同样合理的风格)才询问用户。

Place it AND wire it up — don't just dump a file

放置并配置图像——不要仅生成文件

When the user asks for an image for a specific surface (a blog post, a landing page, an OG card, a README, a component, etc.), you are responsible for the whole job, not just the PNG. Always do these in order:
  1. Pick the correct on-disk location for that surface. Look at what already exists and match it. Examples:
    • Blog hero → wherever existing blog images live (e.g.
      apps/<app>/public/static/blog/<slug>.png
      ).
    • Landing page asset → wherever other landing assets live (e.g.
      apps/<app>/public/static/marketing/...
      ).
    • README / docs image →
      docs/images/
      ,
      assets/
      , or next to the doc.
    • Component-specific asset → next to the component or in its
      public/
      /
      assets/
      folder.
    Use the file's slug, component name, or section name for the filename. Don't invent a new convention if one already exists.
  2. Wire the image up so it actually shows where the user wanted it. This is not optional. Examples:
    • Blog post MDX → update the
      image:
      (or equivalent) frontmatter field to point at the new path. Replace any placeholder Unsplash/stock URL.
    • Landing page section → import or reference the new asset in the relevant component/JSX.
    • OG image → update the
      <meta property="og:image">
      / metadata config.
    • README → add the appropriate Markdown image tag.
  3. Match existing conventions for paths (relative vs
    /static/...
    vs
    @/assets/...
    ), file format (png/webp/jpg), and any wrapper components (
    next/image
    , custom
    <Image>
    , etc.).
  4. Don't ask first. If the user asked for an image for a known surface, do the placement + wiring automatically and tell them what you changed at the end. Only ask when the destination is genuinely ambiguous.
当用户要求为特定载体(博客文章、落地页、OG卡片、README、组件等)生成图像时,您需要负责完整的工作,而非仅生成PNG文件。请始终按以下步骤操作:
  1. 选择正确的磁盘位置。查看现有文件的存放位置并遵循相同规则。示例:
    • 博客首图 → 现有博客图像的存放位置(例如
      apps/<app>/public/static/blog/<slug>.png
      )。
    • 落地页素材 → 其他落地页素材的存放位置(例如
      apps/<app>/public/static/marketing/...
      )。
    • README/文档图像 →
      docs/images/
      assets/
      或文档旁。
    • 组件专属素材 → 组件旁或其
      public/
      /
      assets/
      目录中。
    使用文件的slug、组件名称或板块名称作为文件名。如果已有命名规则,请勿自行创建新规则。
  2. 配置图像使其正常显示。这是必须完成的步骤。示例:
    • 博客文章MDX → 更新
      image:
      (或等效的)前置字段,指向新路径。替换任何占位的Unsplash/图库URL。
    • 落地页板块 → 在相关组件/JSX中导入或引用新素材。
    • OG图像 → 更新
      <meta property="og:image">
      /元数据配置。
    • README → 添加适当的Markdown图像标签。
  3. 匹配现有规范包括路径(相对路径/
    /static/...
    /
    @/assets/...
    )、文件格式(png/webp/jpg)和任何包装组件(
    next/image
    、自定义
    <Image>
    等)。
  4. 不要先询问用户。如果用户要求为已知载体生成图像,请自动完成放置和配置操作,并在最后告知用户您所做的更改。仅在目标位置确实存在歧义时才询问用户。

Errors — surface, don't hide

错误处理——直接告知,不要隐藏

If any of the following happen, stop immediately and report the error to the user. Do not retry, do not change the model, do not change the prompt.
  • OPENAI_API_KEY is not set
    → ask the user how to provide it.
  • openai package not installed
    → tell the user to run
    pip install --upgrade openai
    .
  • 403 "organization must be verified" → tell the user to verify at platform.openai.com/settings/organization/general. Do not switch models.
  • 400 size error → report it; let the user pick a valid size.
  • 400 about transparent background → report it;
    gpt-image-2
    doesn't support transparency.
  • Any other API error → report verbatim and stop.
如果发生以下任何情况,请立即停止并向用户报告错误。不要重试,不要切换模型,不要修改提示词。
  • OPENAI_API_KEY is not set
    → 询问用户提供密钥的方式。
  • openai package not installed
    → 告知用户运行
    pip install --upgrade openai
  • 403错误提示“organization must be verified” → 告知用户前往platform.openai.com/settings/organization/general完成验证。不要切换模型。
  • 400尺寸错误 → 报告错误;让用户选择有效的尺寸。
  • 400透明背景相关错误 → 报告错误;
    gpt-image-2
    不支持透明背景。
  • 任何其他API错误 → 原封不动报告并停止操作。