image editing

Complete editing with reference images and prompt words to distinguish multipart and JSON requests.

Select edit model

First confirm that the model supports image editing and the number of required reference images. Some models only support generation, and some allow multiple images or masks; unified endpoints will not automatically complete capabilities that the model does not have.

multipart example

Models that accept the OpenAI multipart editing protocol can use:

curl --fail-with-body https://dunduntoken.com/v1/images/edits \
 -H "Authorization: Bearer $DUNDUN_API_KEY" \
 -F "model=IMAGE_EDIT_MODEL_ID" \
 -F "prompt=保留杯子的形状,将杯身改为深绿色" \
 -F "image=@./reference.png"

The multipart boundary is automatically generated by curl. Do not set Content-Type: application/json manually. Different models may require JSON, image[], or their own reference graph fields, and a contract supported by that model must be used.

Masks and results

Mask size, transparency, and semantics are handled as specified by the model. Without a mask, you cannot assume that the model will necessarily only modify a certain area. Verify subject, text, and composition before getting down to business.

For the response saving method, see Image Generation. Avoid logging image Base64 or full links with private signatures.

Preparation before operation

  1. Select an actual model that explicitly supports editing.
  2. Prepare the materials you have the right to use and confirm the file format, size and dimensions.
  3. First use a single image and clear prompts to verify, then add multiple images, masks or other parameters.
  4. Set an independent file name for the output and retain the original input image for comparison.

Python multipart example

import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["DUNDUN_API_KEY"], base_url="https://dunduntoken.com/v1", timeout=600, max_retries=0)
with open("reference.png", "rb") as image:
    result = client.images.edit(
        model="IMAGE_EDIT_MODEL_ID", image=image,
        prompt="保留杯子的形状,将杯身改为深绿色",
    )
for item in result.data or []:
    print("已返回图片" if item.b64_json or item.url else "未发现图片载荷")

For the saving logic, see Image Generation. This example only works for models that accept the multipart protocol.

##Multiple images and masks

Give each image a clear purpose, such as subject, style, and composition. Field image, duplicate image[] and JSON reference image array have their own contracts and are not interchangeable. The mask needs to handle the transparent area and size according to the target model definition to avoid using the preview image as a mask.

Fault location

415 Check transfer type, 413 Check volume, 400 Check model, field and material quantity. Returning 200 still requires confirmation of the actual image payload. If the editor only generates new images, check whether you selected the wrong model to generate or the client did not upload the materials.