> Treat every model id, price, size, length and limit in this documentation as an illustration of the shape of the value, never as a constant to hardcode. The live values are served by GET /v1/models and GET /public/models on the HyperFlow HI API.

# Edit images

POST https://api.hi.hyperflow.fun/v1/images/edits
Content-Type: multipart/form-data

Changes one or more images following a prompt, optionally only where a mask is transparent.

Reference: https://docs.hi.hyperflow.fun/api/endpoints/images/edit-image

## Authentication

- `Authorization` header (bearer token, required) — Your API key, `sk-...`, from Console → API keys.

## Request

### Body (multipart/form-data)

This endpoint expects a multipart form with multiple files.

- `model` (string, required)
- `prompt` (string, required)
- `image` (file, required) — The image to edit.
- `mask` (file, optional) — A PNG whose transparent areas mark what to change.
- `n` (integer, optional)
- `size` (string, optional)
- `quality` (string, optional)
- `background` (enum, optional)
- `output_format` (enum, optional)
- `user` (string, optional)
- `metadata` (map from string to string, optional)

## Response

### 200

The edited images, inline as base64 in `data[].b64_json`.

- `created` (integer, optional)
- `data` (list of ImageResponseDataItems, optional)
- `usage` (ImageResponseUsage, optional) — Token usage, for models billed by tokens.

## Errors

### 400 Bad Request Error

A parameter is wrong, the model doesn't take that content or option, or the model rejected the request.

- `error` (ErrorResponseError, required)

### 401 Unauthorized Error

The key is missing, wrong, deleted or switched off. `GET /v1/models` and the video reads use the codes `invalid_api_key` and `key_disabled`.

- `error` (ErrorResponseError, required)

### 402 Payment Required Error

The available balance can't cover the most this request could cost.

- `error` (ErrorResponseError, required)

### 403 Forbidden Error

A limit set on your account was reached.

- `error` (ErrorResponseError, required)

### 404 Not Found Error

No such model or video. The video reads use the code `not_found`.

- `error` (ErrorResponseError, required)

### 422 Unprocessable Entity Error

The model answered without an image, for example because it declined the prompt.

- `error` (ErrorResponseError, required)

### 429 Too Many Requests Error

Too many requests from this address (code `rate_limited`), or from this key.

- `error` (ErrorResponseError, required)

### 502 Bad Gateway Error

The model's hosts couldn't answer. Retry shortly.

- `error` (ErrorResponseError, required)

### 503 Service Unavailable Error

The model's hosts are busy, or billing is briefly unavailable. Retry shortly.

- `error` (ErrorResponseError, required)

## Types

### ImageResponseDataItems

- `b64_json` (string, optional) — The image, base64-encoded.
- `revised_prompt` (string, optional, nullable)

### ImageResponseUsage

Token usage, for models billed by tokens.

### ErrorResponseError

- `message` (string, required) — What went wrong, written to be read.
- `type` (string, optional) — OpenAI's error type, such as `invalid_request_error`.
- `code` (string, optional) — On inference endpoints, the HTTP status as a string, such as `"402"`. Elsewhere a named code, such as `invalid_api_key`, `key_disabled`, `not_found`, `video_not_ready`, `video_expired` or `rate_limited`.

## Examples

**Request**

```json
{
  "image": "<file: <file1>>",
  "mask": "<file: <file1>>",
  "model": "google/gemini-2.5-flash-image",
  "prompt": "Add a tall green plant by the window"
}
```

**Response**

```json
{
  "created": 1782886429,
  "data": [
    {
      "b64_json": "iVBORw0KGgo..."
    }
  ]
}
```

**SDK Code**

```python
import base64
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.hi.hyperflow.fun/v1", api_key=os.environ["HYPERFLOW_API_KEY"])

response = client.images.edit(
    model="google/gemini-2.5-flash-image",
    image=open("room.png", "rb"),
    mask=open("window-mask.png", "rb"),
    prompt="Add a tall green plant by the window",
)
open("room-edited.png", "wb").write(base64.b64decode(response.data[0].b64_json))

```

```typescript
import fs from 'node:fs'
import OpenAI from 'openai'

const client = new OpenAI({ baseURL: 'https://api.hi.hyperflow.fun/v1', apiKey: process.env.HYPERFLOW_API_KEY })

const response = await client.images.edit({
  model: 'google/gemini-2.5-flash-image',
  image: fs.createReadStream('room.png'),
  mask: fs.createReadStream('window-mask.png'),
  prompt: 'Add a tall green plant by the window',
})
fs.writeFileSync('room-edited.png', Buffer.from(response.data?.[0]?.b64_json ?? '', 'base64'))

```

```javascript
import fs from 'node:fs'

const form = new FormData()
form.append('model', 'google/gemini-2.5-flash-image')
form.append('prompt', 'Add a tall green plant by the window')
form.append('image', await fs.openAsBlob('room.png', { type: 'image/png' }), 'room.png')
form.append('mask', await fs.openAsBlob('window-mask.png', { type: 'image/png' }), 'window-mask.png')

const response = await fetch('https://api.hi.hyperflow.fun/v1/images/edits', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.HYPERFLOW_API_KEY}` },
  body: form,
})
console.log(await response.json())

```

```csharp
using System.Net.Http.Headers;

using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("HYPERFLOW_API_KEY"));

using var form = new MultipartFormDataContent();
form.Add(new StringContent("google/gemini-2.5-flash-image"), "model");
form.Add(new StringContent("Add a tall green plant by the window"), "prompt");

var image = new ByteArrayContent(File.ReadAllBytes("room.png"));
image.Headers.ContentType = new MediaTypeHeaderValue("image/png");
form.Add(image, "image", "room.png");

var mask = new ByteArrayContent(File.ReadAllBytes("window-mask.png"));
mask.Headers.ContentType = new MediaTypeHeaderValue("image/png");
form.Add(mask, "mask", "window-mask.png");

var response = await client.PostAsync("https://api.hi.hyperflow.fun/v1/images/edits", form);
Console.WriteLine(await response.Content.ReadAsStringAsync());

```

```swift
import Foundation

let boundary = UUID().uuidString
var body = Data()

func field(_ name: String, _ value: String) {
    body.append("--\(boundary)\r\nContent-Disposition: form-data; name=\"\(name)\"\r\n\r\n\(value)\r\n".data(using: .utf8)!)
}

func image(_ name: String, _ path: String) throws {
    body.append("--\(boundary)\r\nContent-Disposition: form-data; name=\"\(name)\"; filename=\"\(path)\"\r\nContent-Type: image/png\r\n\r\n".data(using: .utf8)!)
    body.append(try Data(contentsOf: URL(fileURLWithPath: path)))
    body.append("\r\n".data(using: .utf8)!)
}

field("model", "google/gemini-2.5-flash-image")
field("prompt", "Add a tall green plant by the window")
try image("image", "room.png")
try image("mask", "window-mask.png")
body.append("--\(boundary)--\r\n".data(using: .utf8)!)

var request = URLRequest(url: URL(string: "https://api.hi.hyperflow.fun/v1/images/edits")!)
request.httpMethod = "POST"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["HYPERFLOW_API_KEY"]!)", forHTTPHeaderField: "Authorization")
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

let (data, _) = try await URLSession.shared.upload(for: request, from: body)
print(String(decoding: data, as: UTF8.self))

```

```php
<?php

$ch = curl_init('https://api.hi.hyperflow.fun/v1/images/edits');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('HYPERFLOW_API_KEY')],
    CURLOPT_POSTFIELDS => [
        'model' => 'google/gemini-2.5-flash-image',
        'prompt' => 'Add a tall green plant by the window',
        'image' => new CURLFile('room.png', 'image/png'),
        'mask' => new CURLFile('window-mask.png', 'image/png'),
    ],
]);

echo curl_exec($ch);
curl_close($ch);

```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class EditImage {
    public static void main(String[] args) throws Exception {
        String boundary = UUID.randomUUID().toString();
        List<byte[]> parts = new ArrayList<>();
        field(parts, boundary, "model", "google/gemini-2.5-flash-image");
        field(parts, boundary, "prompt", "Add a tall green plant by the window");
        image(parts, boundary, "image", Path.of("room.png"));
        image(parts, boundary, "mask", Path.of("window-mask.png"));
        parts.add(("--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8));

        HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.hi.hyperflow.fun/v1/images/edits"))
            .header("Authorization", "Bearer " + System.getenv("HYPERFLOW_API_KEY"))
            .header("Content-Type", "multipart/form-data; boundary=" + boundary)
            .POST(HttpRequest.BodyPublishers.ofByteArrays(parts))
            .build();
        HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }

    static void field(List<byte[]> parts, String boundary, String name, String value) {
        parts.add(("--" + boundary + "\r\nContent-Disposition: form-data; name=\"" + name + "\"\r\n\r\n" + value + "\r\n")
            .getBytes(StandardCharsets.UTF_8));
    }

    static void image(List<byte[]> parts, String boundary, String name, Path path) throws Exception {
        parts.add(("--" + boundary + "\r\nContent-Disposition: form-data; name=\"" + name + "\"; filename=\""
            + path.getFileName() + "\"\r\nContent-Type: image/png\r\n\r\n").getBytes(StandardCharsets.UTF_8));
        parts.add(Files.readAllBytes(path));
        parts.add("\r\n".getBytes(StandardCharsets.UTF_8));
    }
}

```

```go
package main

import (
	"bytes"
	"fmt"
	"io"
	"mime/multipart"
	"net/http"
	"net/textproto"
	"os"
)

func addImage(w *multipart.Writer, field, path string) error {
	data, err := os.ReadFile(path)
	if err != nil {
		return err
	}
	header := textproto.MIMEHeader{}
	header.Set("Content-Disposition", fmt.Sprintf(`form-data; name=%q; filename=%q`, field, path))
	header.Set("Content-Type", "image/png")
	part, err := w.CreatePart(header)
	if err != nil {
		return err
	}
	_, err = part.Write(data)
	return err
}

func main() {
	var body bytes.Buffer
	w := multipart.NewWriter(&body)
	w.WriteField("model", "google/gemini-2.5-flash-image")
	w.WriteField("prompt", "Add a tall green plant by the window")
	if err := addImage(w, "image", "room.png"); err != nil {
		panic(err)
	}
	if err := addImage(w, "mask", "window-mask.png"); err != nil {
		panic(err)
	}
	w.Close()

	req, _ := http.NewRequest("POST", "https://api.hi.hyperflow.fun/v1/images/edits", &body)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("HYPERFLOW_API_KEY"))
	req.Header.Set("Content-Type", w.FormDataContentType())

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	out, _ := io.ReadAll(res.Body)
	fmt.Println(string(out))
}

```

```ruby
require "net/http"
require "uri"

uri = URI("https://api.hi.hyperflow.fun/v1/images/edits")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('HYPERFLOW_API_KEY')}"
request.set_form(
  [
    ["model", "google/gemini-2.5-flash-image"],
    ["prompt", "Add a tall green plant by the window"],
    ["image", File.open("room.png"), { filename: "room.png", content_type: "image/png" }],
    ["mask", File.open("window-mask.png"), { filename: "window-mask.png", content_type: "image/png" }],
  ],
  "multipart/form-data"
)

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
puts response.body

```