AI 服务/图像生成

编辑图像

接口说明:同步编辑图像,基于参考图与指令进行编辑。

调用本接口前,请先请求「图像编辑模型」接口(GET /api/ai/models/image/edit),获取当前可用的模型列表及各模型支持的尺寸、最大输入图片数与价格,再据此填写本接口参数。

图像编辑为图生图:必须传入参考图片 image,按提示词在其基础上修改、重绘或风格化。如需仅用文字生成全新图像(文生图),请使用「生成图像」接口。

如已在使用 OpenAI SDK 或生态工具,可改用 OpenAI 兼容端点「OpenAI 图像编辑」。

post/api/ai/image/edit

Request

Request body

modelstring required

图像编辑模型名称。先调用「图像编辑模型」接口(GET /api/ai/models/image/edit),传入其返回的 data[n].name;各模型支持的尺寸、最大输入图片数与价格以该接口返回为准。

promptstring required

编辑描述

maskstring

遮罩图片 URL,用于局部重绘(可选)。需为与 image 尺寸一致的 PNG 图片:完全透明(alpha 为 0)的区域表示需要按提示词重绘的部分,不透明区域保持原图不变。不传时对整张图片进行编辑。

ninteger

生成图片数量

sizestring

图像尺寸。可选值随模型而不同,以「图像编辑模型」接口返回的 data[n].sizes 为准;不同尺寸的价格不同,见 data[n].pricing。当前示例使用 1024x1024,对应最低价格 1 积分。

response_format'url' | 'b64_json'

返回格式

Example request

{
  "model": "gpt-image-2",
  "prompt": "Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style.",
  "n": 1,
  "size": "1024x1024",
  "response_format": "url"
}

Response

请求已被服务处理。业务是否成功以响应体 code === 0 为准。

codeinteger required

业务状态码。0 表示成功,非 0 表示业务错误。

messagestring required

响应消息。

requestIdstring

请求 ID。

timestampinteger

错误响应时间戳,Unix 毫秒。

Changes

No recorded changes to this operation across all 2 revisions of this API.