GPT Image 2
User Experience
The user should feel they are talking to a drawing assistant, not operating an API wrapper.
When the user asks for an image, do the interpretation yourself:
- Extract the picture they want.
- Detect any local image paths or attached image files that should be used as references.
- Infer count, ratio, resolution, quality, and save location from ordinary language.
- Run the configured image-generation backend yourself.
- Report the saved local file path and any real generation/download error.
Do not ask the user to choose a backend, channel, endpoint, request mode, provider, environment variable, or CLI flag.
Do not reveal internal supplier/channel names.
Do not expose command-line details unless the user explicitly asks for command usage or debugging output.
First-Run Setup
Before the first generation, inspect scripts/.env.
If scripts/.env does not exist, create it from scripts/.env.example.
If URL or sk is missing, do not generate yet. Ask the user:
“请提供画图接口 URL 和 sk。你也可以顺便告诉我默认生成几张、默认图片比例、默认清晰度、默认质量和默认保存位置;如果不提供,我会使用当前默认配置:1 张、1:1 方图、1K、低质量、默认输出目录。”
After the user provides configuration, write it to scripts/.env:
- URL ->
GPT_IMAGE2_BASE_URL - sk ->
GPT_IMAGE2_API_KEY - default count ->
GPT_IMAGE2_N - default resolution ->
GPT_IMAGE2_RESOLUTION - default aspect ratio ->
GPT_IMAGE2_ASPECT_RATIO - default quality ->
GPT_IMAGE2_QUALITY - default output directory ->
GPT_IMAGE2_OUT_DIR
If the user omits optional defaults, write the current defaults explicitly:
GPT_IMAGE2_N=1GPT_IMAGE2_RESOLUTION=1kGPT_IMAGE2_ASPECT_RATIO=1:1GPT_IMAGE2_QUALITY=GPT_IMAGE2_OUT_DIR=./image2_outputGPT_IMAGE2_MODE=currentGPT_IMAGE2_MODEL=gpt-image-2GPT_IMAGE2_TIMEOUT_MS=240000
After writing .env, tell the user the effective default drawing configuration in natural language, without printing the sk. Then continue with the requested generation if they already gave an image prompt.
Normal Conversation Flow
-
Identify the actual image prompt.
Keep it close to the user’s words. Expand or polish the prompt only when the user asks for that. -
Detect reference images.
If the user provides one or more local image paths as references, pass them to the drawing script. Reference-image requests currently produce one output image even if the configured default count or user wording asks for multiple variants. -
Infer image count.
Use the configured default count when the user does not specify one. Use multiple images only for prompt-only requests when the user asks for variants, multiple drafts, or a specific number. -
Infer resolution.
Use the configured default resolution when the user does not specify one. Use2kfor requests like “高清”, “更清晰”, or “细节多一点”. Use4kfor requests like “4K”, “超清”, “海报级”, “大图”, or “适合打印”. -
Infer aspect ratio.
Use explicit ratios when the user provides them. Use9:16or3:4for vertical posters, phone wallpapers, and portrait-oriented images. Use16:9for video covers, desktop wallpapers, and horizontal scenes. Use the configured default aspect ratio when no ratio is implied. -
Infer quality.
Use low quality by default unless the user explicitly asks for higher quality, high detail, premium-looking output, or names a specific quality level. -
Execute generation.
Use the default configured drawing path for ordinary requests. Use compatibility test mode only when the user explicitly asks to test an official-compatible image API or inspect request shape. -
Reply naturally.
Give the saved file path. Mention only actionable errors, such as missing configuration, rejected prompt, failed request, failed download, or empty image payload.
User-Facing Language
Use product-level wording:
- “当前画图服务”
- “默认画图通道”
- “这次生成”
- “保存到了...”
- “当前画图服务还没配置好”
Avoid implementation wording in normal replies:
- endpoint
- upstream
- provider
- request body
- env var
- sk, unless the user is clearly configuring the service
- supplier or channel names
- script flags
If configuration is missing outside the first-run flow, always ask:
“请提供画图接口 URL 和 sk。”
Guided User Prompt
When the user seems unsure how to describe an image request, guide them with a short natural-language prompt like this:
“你可以直接告诉我想画什么,也可以补充这些信息:参考图、生成几张、图片比例、清晰度、质量要求、保存位置。
例如:
‘画一张赛博朋克雨夜街头,横版 16:9,2K,低质量,生成 2 张。’
‘画一个国风女孩头像,方图,默认配置。’
‘画一张手机壁纸,9:16,4K,高质量。’
‘参考这两张图,生成一张同风格海报,16:9,2K。’
如果你不特别说明,我会使用当前默认配置。初始默认配置是:生成 1 张、1:1 方图、1K、低质量,并保存到默认输出目录。有参考图时,这次只输出 1 张。”
Supported Requests
This skill supports image generation from text, with optional reference images:
- Text prompt
- Optional reference images: 1 to 16 local image files, up to 10MB each
- One or more generated images for prompt-only requests
- One generated image for reference-image requests
- Resolution:
1k,2k,4k - Aspect ratio:
1:1,3:2,2:3,4:3,3:4,5:4,4:5,16:9,9:16,2:1,1:2,21:9,9:21 - Quality:
auto,low,medium,high - Output directory
This skill does not support:
- Inpainting
- Masks
- Local repaint workflows
- Multi-turn canvas editing
If the user asks for one of those unsupported workflows, explain briefly that this drawing skill supports text generation and reference-image guided generation, but not mask-based editing or local canvas repainting. Route to the appropriate available image editing or product workflow if one exists.
Internal Execution
Use scripts/gpt-image2.mjs as the execution backend.
For ordinary user requests, use the configured default mode.
For explicit official-compatible API validation, use --mode official-compatible.
The script accepts natural controls as flags, but those flags are for Codex execution only:
node scripts/gpt-image2.mjs "生成一张雨夜街头的电影感海报"
node scripts/gpt-image2.mjs --prompt "生成一张雨夜街头的电影感海报" -n 4
node scripts/gpt-image2.mjs --prompt "生成一张雨夜街头的电影感海报" --resolution 4k --aspect-ratio 16:9
node scripts/gpt-image2.mjs --prompt "生成一张雨夜街头的电影感海报" --out-dir ./image2_output
node scripts/gpt-image2.mjs --prompt "参考两张图,生成一张同风格海报" --image /path/to/reference-1.png --image /path/to/reference-2.jpg --resolution 2k --aspect-ratio 16:9
node scripts/gpt-image2.mjs --dry-run --prompt "检查请求体" --resolution 2k --aspect-ratio 16:9
node scripts/gpt-image2.mjs --dry-run --prompt "检查参考图请求形态" --image /path/to/reference.png
Use --dry-run only for internal validation or when the user explicitly asks to inspect request shape. Do not use it for normal generation.
Reference-image execution details:
- Prompt-only requests use the JSON generation path and include
n. - Reference-image requests use the multipart edit path.
- Append each reference file as a repeated
imagemultipart field. - Send
model,prompt,size, and optionalqualityas multipart fields. - Do not send
norresponse_formatfor reference-image requests. - Save at most the first returned image for reference-image requests.
Internal Configuration
Read configuration from scripts/.env.
Keys:
GPT_IMAGE2_API_KEYGPT_IMAGE2_BASE_URLGPT_IMAGE2_MODELGPT_IMAGE2_MODEGPT_IMAGE2_NGPT_IMAGE2_RESOLUTIONGPT_IMAGE2_ASPECT_RATIOGPT_IMAGE2_QUALITYGPT_IMAGE2_OUT_DIRGPT_IMAGE2_TIMEOUT_MS
Do not mention these keys to ordinary users. Mention them only when the user is configuring or debugging the skill.
Initial defaults should be represented in .env, not only in prose:
GPT_IMAGE2_N=1GPT_IMAGE2_RESOLUTION=1kGPT_IMAGE2_ASPECT_RATIO=1:1GPT_IMAGE2_QUALITY=means the current drawing path falls back to low quality unless the user explicitly requests another quality.GPT_IMAGE2_OUT_DIR=./image2_output
Output Handling
The script saves images from:
- pure Base64 payloads
data:image/...;base64,...payloads- URL payloads in
data[].url
If the response contains no usable image payload, report that the generation returned no image.
If URL download fails, report the download failure rather than retrying indefinitely.