Skip to main content

Image edits

/v1/images/edits takes one or more input images and a prompt and returns edited images. The request is multipart form data, as in the OpenAI API, and the gateway forwards it to the provider behind the public model name. Costs are recorded per image, uploads are limited by the gateway's file size settings, and the prompt goes through the same guardrails as every other call.

Scenario​

An online shop wants product photos placed on new backgrounds. A batch job uploads each product image with a prompt describing the scene, and the gateway returns the edited image. The admin set mode: image_edit on the model so the Playground offers it for image edits and health checks use the right request.

Steps​

  1. Register the model. In the Admin UI open Models + Endpoints (/ui/models-and-endpoints), click Add Model, pick the Provider, choose the model, set the Public Model Name to gpt-image-1 and set Mode to Image Edit - /images/edits, then click Add Model.

    model_list:
    - model_name: gpt-image-1
    spanway_params:
    model: openai/gpt-image-1
    api_key: os.environ/OPENAI_API_KEY
    model_info:
    mode: image_edit
  2. Create a key in Virtual Keys (/ui/api-keys) and pick the model under Models.

  3. Send an edit as multipart form data.

    curl -X POST http://localhost:4000/v1/images/edits \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -F "model=gpt-image-1" \
    -F "image[]=@product.png" \
    -F "prompt=Place the product on a wooden table in soft daylight" \
    -F "size=1024x1024"
  4. Try it in the browser. Open Playground (/ui/playground), set Endpoint Type to /v1/images/edits, pick the model, drop up to ten images on the upload area, type the prompt and send.

  5. Check the cost in Logs (/ui/logs).

Expected result​

{
"created": 1760441234,
"data": [{"b64_json": "iVBORw0KGgo..."}]
}

To save the image from the command line, pipe .data[0].b64_json through a base64 decoder.

Request fields​

FieldMeaning
image or image[]One or more input images.
maskOptional PNG whose transparent areas mark the region to edit.
promptDescription of the edit.
n, size, quality, response_format, userAs for generation.

Bedrock Nova Canvas edits are supported for models with the supports_nova_canvas_image_edit flag.

Errors​

StatusWhat it meansFix
400 BadRequestErrorNo image was sent, the image format is not accepted, or mask does not match the image size.Send PNG, JPEG or WebP images, and a mask of the same size.
413The request is larger than general_settings.max_request_size_mb, 100 MB by default.Shrink the image or raise the limit.
422 Cannot specify both 'image' and 'image[]'The form sent the same image under both field names.Send image or image[], not both.
422 Cannot specify both 'mask' and 'mask[]'The same for the mask.Send one mask field.
422 'image' must be provided as a multipart file upload, not a string.The image was sent as text, for example a URL in a form field.Upload the file with -F "image=@photo.png".
400 ContentPolicyViolationErrorThe provider's safety filter refused the prompt or the image.Change the prompt or the image.
401 AuthenticationErrorThe key is missing, wrong or expired.Use a live key.
403 PermissionDeniedErrorThe key may not use the model.Add the model to the key.
429 RateLimitErrorBudget or rate limit reached.Raise the limit.

Providers​

The gateway's endpoint support matrix marks 3 provider integrations as supporting this endpoint:

Azure AI, Black Forest Labs (black_forest_labs), Stability AI.