跳轉到主要內容
POST
/
v1
/
images
/
edits
Edit image
curl --request POST \
  --url https://api.dgrid.ai/v1/images/edits \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form image='@example-file' \
  --form 'prompt=<string>' \
  --form mask='@example-file' \
  --form 'model=<string>' \
  --form n=123 \
  --form 'size=<string>' \
  --form 'response_format=<string>' \
  --form 'user=<string>'
{
  "created": 123,
  "data": [
    {
      "url": "<string>",
      "b64_json": "<string>",
      "revised_prompt": "<string>"
    }
  ],
  "usage": {
    "total_tokens": 123,
    "input_tokens": 123,
    "output_tokens": 123,
    "input_tokens_details": {
      "text_tokens": 123,
      "image_tokens": 123
    }
  }
}
本頁使用與 編輯圖像 相同的 images/edits 操作,上方 playground 已預先填入通用 OpenAI 風格的編輯結構(imagemaskprompt 等)。以下說明 wanx-v1 類模型的 Qwen 專用請求格式。
Qwen 圖像編輯模型接受另一種 JSON 請求格式:將編輯指令與來源圖像參照包在 input.messages 中,而不是透過 multipart form data 上傳 imagemask 檔案。若要使用這種格式,請在 playground 的請求本文中同時提供 modelinput

Qwen 專用請求欄位

欄位類型必填說明
modelstring模型識別碼,例如 wanx-v1
inputobject在請求本文中傳送的輸入包裝物件,用來取代 multipart 的 imagemask 欄位。
input.messagesarray巢狀於 input 之下的 messages 陣列。
input.messages[].rolestring訊息角色,例如 user
input.messages[].contentstring編輯指令,以及任何被參照的來源圖像。
來源圖像可以直接在 input.messages[].content 中以內嵌方式參照(例如 URL 或嵌入式參照),而不必另外上傳 multipart 檔案。

範例:編輯圖像

{
  "model": "wanx-v1",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": "Remove the background and replace it with a solid white backdrop."
      }
    ]
  }
}

回應欄位

回應遵循標準圖像編輯結構:
created
integer
建立時間戳。
data
array
生成圖像條目。

回應範例

200
{
  "created": 1719859200,
  "data": [
    {
      "url": "https://cdn.dgrid.ai/generated/edited-abc123.png",
      "b64_json": "",
      "revised_prompt": "The subject with background removed and replaced with a solid white backdrop."
    }
  ]
}

授權

Authorization
string
header
必填

Your DGrid API key. All endpoints use Authorization: Bearer <DGRID_API_KEY>.

主體

image
file
必填

Source image in PNG format, under 4 MB.

prompt
string
必填

Editing instruction.

mask
file

Optional mask image.

model
string

Target image model.

n
integer

Number of outputs.

size
string

Output size.

response_format
string

Response format.

user
string

End-user identifier.

回應

Edited images in the image generation response format.

created
integer

Creation timestamp.

data
object[]

Generated image entries.

usage
object