image_edit
Edit an input image using a text prompt: replace background, change objects, or refine details. Supports localized edits via alpha mask and output sizes up to 4K.
Instructions
图像编辑(image-to-image,单张输入)。当前线路支持 1K/2K/4K。
[WHAT] 接受 1 张本地图片 + 修改指令,输出修改后的图。
[WHEN TO USE]
用户提供 1 张图(路径或刚刚生成的图)且要"改 / 替换 / 加 / 去掉某部分" → 用此 tool。
如果用户没提供图想从零生成 → 改用 image_generate。
如果用户提供了多张图想"批量改"(每张做同样操作)→ 改用 image_batch_edit。
如果用户用多张图作风格参考想画一张新的 → 用 image_multi_reference。
[尺寸能力](2026-08-14 当前线路实测)
1K:gpt-image-2 与 gpt-image-2-openai 的 1024×1024 edits 均成功并精确返回。
2K:自动切 gpt-image-2-openai;2048×1152 edits 成功并精确返回。
4K:自动切 gpt-image-2-openai;3840×2160 edits 成功并精确返回。
[当前线路]
参考图 4K 的旧线路硬阻断已移除;1K/2K/4K 均统一走 /v1/images/edits。
2K/4K 自动使用 gpt-image-2-openai,并通过跨进程锁串行请求高质量队列。
始终通过 saved.actual_size 核对后端实际返回像素。
[路由实现](实测确定)
所有尺寸统一走 /v1/images/edits multipart(米醋唯一真正消费输入图的端点)。 Images API 返回错误时直接报错,不把图像模型转发到不兼容的 /v1/chat/completions。
mask 现已在所有尺寸支持(不再区分 1K/2K)。
[MASK 工作原理]
mask_path 指向一张 PNG,尺寸应与 image_path 一致。
mask 中 alpha=0(透明) 的像素 = 要修改的区域。
alpha=255(不透明)的像素 = 要保持原样。
不传 mask 则模型自由决定改哪里。
Args: prompt: 修改指令,越具体越好。例:"change the background to deep navy with stars, keep the subject pixel-identical". image_path: 输入图的绝对或相对路径。PNG / JPG / WebP 都支持。 mask_path: 可选 alpha mask PNG 路径,透明区即编辑区。所有尺寸均生效。 size: 输出 size。W/H 必须是 16 的倍数;总像素和长宽比规则见 server_info。 "1024x1024" "1280x720" "1024x1536" "1536x1024" "720x1280" ← 1K 档 "2048x2048" "2048x1152" "1152x2048" ← 2K 档(自动高质量线路) "3840x2160" / "2160x3840" ← 4K 档(自动高质量线路) 默认 "1024x1024"。 model: "gpt-image-2"(默认)/ "gpt-image-2-openai"(高质量线路,≥2K 自动切)。 save_dir: 输出目录(必须在安全根目录之下)。默认 ~/Pictures/micu-out 或 MICU_SAVE_DIR。 basename: 文件名前缀(仅 [A-Za-z0-9_-.])。默认 "edit_"。 api_key: 覆盖 MICU_API_KEY;base_url 已锁在启动期 env,运行期不接受。
Returns: dict 含: ok (bool): 是否成功。 model (str): 实际用的模型。 size (str): 请求 size。 used_fallback (bool): 为兼容既有返回结构保留;当前 Image2 模型固定为 False。 saved (dict): { path, size_bytes, actual_size, actual_megapixels }。 notes (list[str]): 决策与提示。
Examples: # 换背景 image_edit(prompt="replace background with a sunset beach", image_path="/p/portrait.jpg")
# 局部修改(mask 生效)
image_edit(prompt="change hair color to silver", image_path="/p/x.png", mask_path="/p/x_mask.png")
# 升细节(2K 自动使用高质量线路)
image_edit(prompt="enhance to cinematic detail, preserve composition", image_path="/p/draft.png", size="2048x2048")
# 4K 参考图编辑(自动使用高质量线路)
image_edit(prompt="preserve composition and refine every detail", image_path="/p/draft.png", size="3840x2160")Common errors: "image_path 不存在" → 检查路径,建议用绝对路径。 "HTTP 524" → 当前高质量队列繁忙;自动策略仍失败时请稍后再试。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| size | No | 1024x1024 | |
| model | No | ||
| prompt | Yes | ||
| api_key | No | ||
| basename | No | ||
| save_dir | No | ||
| mask_path | No | ||
| image_path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||