Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
sizeNo1024x1024
modelNo
promptYes
api_keyNo
basenameNo
save_dirNo
mask_pathNo
image_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries the full burden, and it delivers: discloses the underlying /v1/images/edits endpoint, the automatic 2K/4K switch to gpt-image-2-openai with cross-process lock serialization, the removal of the old 4K hard-block, mask alpha semantics (alpha=0 = edit region, alpha=255 = preserve), actual_size verification, and explicit error conditions (HTTP 524 queue busy, missing image_path). No contradiction with annotations since none are provided.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long, but every section earns its place and the header-based structure ([WHAT], [WHEN TO USE], [尺寸能力], [MASK 工作原理], Args, Returns, Examples, Common errors) makes it highly scannable with the purpose front-loaded. Minor deduction for the dated 尺寸能力 and 路由实现 sections, which are somewhat redundant with the args and could be trimmed; overall this is efficient organization for a high-complexity tool, not padding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 8 parameters, 0% schema coverage, no annotations, and moderate routing complexity, the description is complete: all parameters defined with valid values, usage context with sibling routing, behavioral specifics, a full Returns dict specification, concrete examples for each use case (background swap, mask edit, 2K upscale, 4K refine), and common errors with remediation. Despite the output schema existing, the description also documents the return structure — a bonus that exceeds the baseline requirement.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must fully compensate — and it does. Every one of the 8 parameters is documented beyond the schema: prompt includes a concrete example and advice (the more specific the better); image_path lists supported formats (PNG/JPG/WebP); size enumerates exact valid values per tier with the 16-multiple constraint; model documents auto-switch behavior; save_dir notes the safety-root restriction; basename specifies the character whitelist; api_key explains the base_url lock. This is exemplary compensation for a zero-coverage schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description states a specific verb (edit), resource (single input image), and mutation type (modify/replace/add/remove parts). Clearly names and excludes siblings: image_generate (from scratch), image_batch_edit (batch), image_multi_reference (multi-style-reference). An agent can unambiguously route to this tool based on the WHAT and WHEN TO USE sections alone.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The [WHEN TO USE] section provides crisp selection criteria with explicit alternatives and exclusion conditions: use this when 1 image + edit intent; switch to image_generate if no image; to image_batch_edit for batch ops; to image_multi_reference for style-reference synthesis. Every branch names the sibling and the condition that selects it — nothing is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.