跳转到主要内容
POST
/
v1
/
images
/
edits
Edit images
curl --request POST \
  --url https://api.cometapi.com/v1/images/edits \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form 'prompt=Add a small red ribbon to the paper boat.' \
  --form image='@example-file' \
  --form mask='@example-file'
{
  "created": 1776836647,
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 981,
    "prompt_tokens_details": {
      "cached_tokens_details": {}
    },
    "completion_tokens_details": {},
    "input_tokens": 785,
    "output_tokens": 196,
    "input_tokens_details": {
      "image_tokens": 768,
      "text_tokens": 17,
      "cached_tokens_details": {}
    },
    "claude_cache_creation_5_m_tokens": 0,
    "claude_cache_creation_1_h_tokens": 0
  },
  "data": [
    {
      "b64_json": "<base64-image-data>"
    }
  ]
}

Documentation Index

Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt

Use this file to discover all available pages before exploring further.

使用此路由可在 CometAPI 上通过兼容 OpenAI 的 multipart 上传来编辑现有图像。

在以下情况下使用此路由

  • 你已经有一张源图像,并且希望基于 prompt 进行编辑
  • 你可能需要使用 mask 来实现定向修改
  • 相比普通 JSON 请求,你可以处理 multipart 文件上传

安全的首次请求

  • 从一个 PNG 或 JPG 文件开始
  • 在基础编辑流程跑通之前先跳过 mask
  • 在此路由上发起 GPT 图像编辑请求时,使用 model: "gpt-image-2"
  • 使用一条简短指令,只要求一个可见改动
  • data[0].b64_json 读取编辑后的结果
  • 当你希望获得 JPEG 负载时,设置 output_format: "jpeg"
  • 预期其延迟会高于普通图像生成

模型行为

  • 此路由上的 GPT 图像编辑模型会返回内联 base64 图像数据
  • output_format 控制 b64_json 内部编码后的图像类型
  • response_format 仅在模型支持 URL 输出时才有意义
  • qwen-image-edit 会在同一个 CometAPI 路由后遵循提供商特定的编辑行为

授权

Authorization
string
header
必填

Bearer token authentication. Use your CometAPI key.

请求体

multipart/form-data
image
file
必填

Source image file. Start with one PNG or JPG input for the simplest flow.

prompt
string
必填

Edit instruction describing the change you want.

示例:

"Add a small red ribbon to the paper boat."

model
string
默认值:gpt-image-2

The image editing model to use. Choose a supported model from the Models page.

mask
file

Optional PNG mask. Transparent areas indicate regions that should be edited.

n
string
默认值:1

Number of edited images to return.

quality
enum<string>

Quality setting for models that support it.

可用选项:
high,
medium,
low
response_format
enum<string>

Requested response container when supported by the selected model. GPT image edit models return data[].b64_json; use output_format to choose the encoded image type.

可用选项:
url,
b64_json
output_format
string

Encoded image type for GPT image edit results returned in data[].b64_json. For example, use jpeg for a JPEG payload.

示例:

"jpeg"

size
string

Requested output size when supported by the selected model.

响应

200 - application/json

Edited image result.

created
integer
必填
usage
object
必填
data
object[]
必填