From 50f7d621414124a8858d14155ca1473297fe7c24 Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Fri, 19 Jun 2026 12:22:54 -0500 Subject: [PATCH 1/2] Add support for array syntax for image edit API --- src/cpp/server/server.cpp | 2 +- test/server_sd.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/cpp/server/server.cpp b/src/cpp/server/server.cpp index b95176957..8206ebf74 100644 --- a/src/cpp/server/server.cpp +++ b/src/cpp/server/server.cpp @@ -2805,7 +2805,7 @@ bool Server::parse_n_from_form(const httplib::Request& req, httplib::Response& r bool Server::extract_image_from_form(const httplib::Request& req, httplib::Response& res, nlohmann::json& out) { for (const auto& file_pair : req.form.files) { - if (file_pair.first == "image") { + if (file_pair.first == "image" || file_pair.first == "image[]") { const auto& file = file_pair.second; out["image_data"] = utils::JsonUtils::base64_encode(file.content); out["image_filename"] = file.filename; diff --git a/test/server_sd.py b/test/server_sd.py index e09483a9b..0a327c276 100644 --- a/test/server_sd.py +++ b/test/server_sd.py @@ -664,6 +664,40 @@ def test_020_upscale_basic(self): ) print(f"[OK] Upscale successful ({len(decoded)} bytes)") + def test_021_image_edit_array_field(self): + """Test basic image edit using array parameter syntax.""" + png_bytes = create_minimal_png(256, 256) + print(f"[INFO] Sending image edit request with model {SD_MODEL}") + + response = requests.post( + f"{self.base_url}/images/edits", + files={"image[]": ("test.png", io.BytesIO(png_bytes), "image/png")}, + data={ + "model": SD_MODEL, + "prompt": "A red circle", + "size": "256x256", + "n": "1", + "response_format": "b64_json", + }, + timeout=TIMEOUT_MODEL_OPERATION, + ) + + self.assertEqual( + response.status_code, + 200, + f"Image edit failed with status {response.status_code}: {response.text}", + ) + + result = response.json() + self.assertIn("data", result, "Response should contain 'data' field") + self.assertGreater( + len(result["data"]), 0, "Data should have at least one image" + ) + b64_data = result["data"][0]["b64_json"] + decoded = base64.b64decode(b64_data) + self.assertTrue(decoded[:4] == b"\x89PNG", "Result should be a valid PNG") + print(f"[OK] Image edit successful ({len(decoded)} bytes)") + if __name__ == "__main__": run_server_tests( From 229ca41833640c1655489595e51c0d408386ab4d Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Fri, 19 Jun 2026 12:24:01 -0500 Subject: [PATCH 2/2] Update docs --- docs/api/openai.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/openai.md b/docs/api/openai.md index 0ab7b97fa..84a69c569 100644 --- a/docs/api/openai.md +++ b/docs/api/openai.md @@ -677,7 +677,7 @@ Image Editing API. You provide a source image and a text prompt describing the d | Parameter | Required | Description | Status | |-----------|----------|-------------|--------| | `model` | Yes | The Stable Diffusion model to use (e.g., `Flux-2-Klein-4B`, `SD-Turbo`). | ![Status](https://img.shields.io/badge/available-green) | -| `image` | Yes | The source image file to edit (PNG). Sent as a file in multipart/form-data. | ![Status](https://img.shields.io/badge/available-green) | +| `image` / `image[]` | Yes | The source image file to edit (PNG). Sent as a file in multipart/form-data. | ![Status](https://img.shields.io/badge/available-green) | | `prompt` | Yes | A text description of the desired edit. | ![Status](https://img.shields.io/badge/available-green) | | `mask` | No | An optional mask image (PNG). White areas indicate regions to edit; black areas are preserved. | ![Status](https://img.shields.io/badge/available-green) | | `size` | No | The size of the output image. Format: `WIDTHxHEIGHT` (e.g., `512x512`). Default: `512x512`. | ![Status](https://img.shields.io/badge/available-green) |