跳轉到主要內容
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 驅動的編輯
  • 你可能需要使用遮罩來進行針對性的變更
  • 你可以處理 multipart 檔案上傳,而不是純 JSON 請求

安全的第一個請求

  • 先從一個 PNG 或 JPG 檔案開始
  • 在基礎編輯流程可正常運作之前,先不要使用遮罩
  • 在此路由上進行 GPT 圖像編輯請求時,使用 model: "gpt-image-2"
  • 使用一則簡短指令,要求一項可見的變更
  • data[0].b64_json 讀取編輯後的結果
  • 當你想要 JPEG payload 時,設定 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[]
必填