> 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.

# Image Generation

> Create and edit images from a prompt.

> **Note**
>
> No image models are listed on HyperFlow HI today. This page documents the endpoint for when they join the catalog: check the [Marketplace](https://hi.hyperflow.fun/marketplace) or `GET /v1/models` for models with `"mode": "image"`.

HyperFlow HI generates images through the OpenAI Images API: `POST /v1/images/generations` to create images from a prompt, and `POST /v1/images/edits` to change an image you send.

## Find an image model

* **On the [Marketplace](https://hi.hyperflow.fun/marketplace)**, pick the **Image** type. Each model's page lists its price.
* **From the API**, `GET /v1/models` lists the models you can call; image models have `"mode": "image"`.

```bash
curl https://api.hi.hyperflow.fun/v1/models \
  -H "Authorization: Bearer $HYPERFLOW_API_KEY"
```

## Generate an image

The samples use the OpenAI SDK set up as in the [Quickstart](/quickstart#using-the-openai-sdk), plus `import base64` in Python and `import fs from 'node:fs'` in TypeScript.

**`cURL`**

```bash title="cURL"
curl https://api.hi.hyperflow.fun/v1/images/generations \
  -H "Authorization: Bearer $HYPERFLOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-2.5-flash-image",
    "prompt": "A paper boat on a calm lake, soft morning light",
    "n": 1
  }'
```

**`Python`**

```python title="Python"
response = client.images.generate(
    model="google/gemini-2.5-flash-image",
    prompt="A paper boat on a calm lake, soft morning light",
    n=1,
)
open("boat.png", "wb").write(base64.b64decode(response.data[0].b64_json))
```

**`TypeScript`**

```typescript title="TypeScript"
const response = await client.images.generate({
  model: 'google/gemini-2.5-flash-image',
  prompt: 'A paper boat on a calm lake, soft morning light',
  n: 1,
})
fs.writeFileSync('boat.png', Buffer.from(response.data?.[0]?.b64_json ?? '', 'base64'))
```

The samples use `google/gemini-2.5-flash-image`; any model with `"mode": "image"` works the same way. `size` and `quality` are listed under [Options](#options); send them only if the model offers them.

## Edit an image

`POST /v1/images/edits` takes one or more images and a prompt describing the change. Add a `mask` (a PNG the same size as the image) whose transparent areas mark where to edit. It's sent as a form upload, like OpenAI's.

**`cURL`**

```bash title="cURL"
curl https://api.hi.hyperflow.fun/v1/images/edits \
  -H "Authorization: Bearer $HYPERFLOW_API_KEY" \
  -F model="google/gemini-2.5-flash-image" \
  -F image=@room.png \
  -F mask=@window-mask.png \
  -F prompt="Add a tall green plant by the window"
```

**`Python`**

```python title="Python"
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`**

```typescript title="TypeScript"
import fs from 'node:fs'

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'))
```

## Options

| Parameter       | Generate | Edit | Notes                                                                                       |
| --------------- | -------- | ---- | ------------------------------------------------------------------------------------------- |
| `model`         | ✓        | ✓    | Required                                                                                    |
| `prompt`        | ✓        | ✓    | Required. What to draw, or what to change                                                   |
| `image`         |          | ✓    | Required. The image or images to edit                                                       |
| `mask`          |          | ✓    | Transparent areas mark where to edit                                                        |
| `n`             | ✓        | ✓    | How many images. Each model has its own maximum                                             |
| `size`          | ✓        | ✓    | Such as `1024x1024`, on models that offer it. Defaults to the model's default               |
| `quality`       | ✓        | ✓    | Such as `low`, `medium` or `high`, on models that offer it. Defaults to the model's default |
| `background`    | ✓        | ✓    | `auto`, `transparent` or `opaque`, on models that support it                                |
| `output_format` | ✓        | ✓    | `png`, `jpeg` or `webp`, on models that support it                                          |
| `style`         | ✓        |      | `vivid` or `natural`, on models that support it                                             |

Any other field is removed before the request reaches the model.

### Sizes, qualities and counts

`size`, `quality` and `n` go to the model as you send them, and the model decides what it accepts. A value it doesn't offer is rejected with a `400`, and a rejected request isn't charged. You're held for `n` images and never get more than `n`.

## Response

Every image comes back **inline as base64**, in `data[].b64_json`:

```json
{
  "created": 1782886429,
  "data": [
    { "b64_json": "iVBORw0KGgo..." }
  ],
  "usage": { "input_tokens": 14, "output_tokens": 4160, "total_tokens": 4174 }
}
```

* Images are never returned as links, so `response_format` has no effect. Decode each image and save it.
* `usage` appears for models billed by tokens.

## Best practices

* **Be specific.** Subject, setting, style, lighting and framing all help: "a ceramic mug on an oak desk, top-down, soft window light" beats "a mug".
* **Start small.** Settle the prompt with one image at the model's defaults, then add `size` or `quality` if the model offers them.
* **Ask for one image at a time while exploring.** `n` multiplies the cost.

## Troubleshooting

**`400` "The model rejected the request".** The model doesn't offer the `size`, `quality`, `n` or another option you sent. Leave them out to get the model's defaults, then change one at a time.

**`400` "… is not available right now".** The model can't be used at the moment. Try another image model.

**`422`.** The model answered without an image, for example because it declined the prompt. Rephrase it, or try another image model.

**`404`.** The model id is wrong, or it isn't an image model. Check `GET /v1/models`.

**`402`.** The request is held for every image you ask for; lower `n`, or [top up](https://hi.hyperflow.fun/console/funding).

## Billing

Each image model is priced one of two ways, shown on its page:

* **Per image.** A request is held for `n` images at the model's per-image price.
* **By tokens**, for models that charge for the prompt and the image's tokens. A request is held for its prompt plus a reserve for each image.

Either way, you're charged what the model actually made, and the rest of the hold is released.