# MAI-Image-2.7

## Quick example

Submit one image request, save the returned `id`, and poll until the task is `completed` or `failed`. This API uses asynchronous tasks and PNG URL outputs.

```bash
curl https://api.seedrouter.ai/v1/images/generations \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"model":"mai-image-2.7","prompt":"A university campus poster at dusk, photorealistic style, cinematic lighting","size":"16:9","resolution":"2K"}'
```

```python
import os
import requests

response = requests.post(
    "https://api.seedrouter.ai/v1/images/generations",
    headers={"Authorization": f"Bearer {os.environ['SEEDROUTER_API_KEY']}"},
    json={
        "model": "mai-image-2.7",
        "prompt": "A university campus poster at dusk, photorealistic style, cinematic lighting",
        "size": "16:9",
        "resolution": "2K",
    },
    timeout=60,
)
response.raise_for_status()
task = response.json()
print(task["id"])
```

```javascript
const response = await fetch('https://api.seedrouter.ai/v1/images/generations', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SEEDROUTER_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'mai-image-2.7',
    prompt: 'A university campus poster at dusk, photorealistic style, cinematic lighting',
    size: '16:9',
    resolution: '2K',
  }),
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const task = await response.json();
console.log(task.id);
```

```php
<?php
$ch = curl_init('https://api.seedrouter.ai/v1/images/generations');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('SEEDROUTER_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'model' => 'mai-image-2.7',
        'prompt' => 'A university campus poster at dusk, photorealistic style, cinematic lighting',
        'size' => '16:9',
        'resolution' => '2K',
    ]),
]);
$response = curl_exec($ch);
if ($response === false) throw new RuntimeException('Submission could not be confirmed');
echo $response;
curl_close($ch);
```

## Endpoint and headers

`POST https://api.seedrouter.ai/v1/images/generations`

| Header        | Value                 |
| ------------- | --------------------- |
| Authorization | `Bearer YOUR_API_KEY` |
| Content-Type  | `application/json`    |

Keep the key on your server. An HTTP 200 acknowledges a task; it does not mean the image is ready. Image editing uses the same `/v1/images/generations` endpoint with `image_urls`.

## Parameters

There are **9 accepted fields**. Only `model` and `prompt` are required. Omit optional fields to use defaults; no field accepts `null`. The Playground exposes the fixed model and all 8 editable inputs.

| Field        | Type         | Default  | Constraint                                                                                                           |
| ------------ | ------------ | -------- | -------------------------------------------------------------------------------------------------------------------- |
| `model`      | string       | Required | `mai-image-2.7`                                                                                                      |
| `prompt`     | string       | Required | 1–20000 Unicode characters after trimming                                                                            |
| `n`          | integer      | `1`      | Must be `1`; submit separate tasks for multiple images                                                               |
| `size`       | string       | `1:1`    | Text-to-image only; integer aspect ratio `1:4`–`4:1` or `WIDTHxHEIGHT` (`*` / `×` also accepted); `auto` is rejected |
| `resolution` | string       | `1K`     | `1K` or `2K` (case-insensitive); applies only when `size` is an aspect ratio; `4K` is rejected                       |
| `width`      | integer      | Omitted  | Exact pixel width, `>= 768`; must be paired with `height`; overrides `size` and `resolution`; text-to-image only     |
| `height`     | integer      | Omitted  | Exact pixel height, `>= 768`; must be paired with `width`; `width × height <= 4,194,304` (2048×2048)                 |
| `image_urls` | string array | Omitted  | 1–5 public HTTP(S) image URLs without credentials for single-image editing or multi-image composition                |
| `background` | string       | `auto`   | `auto` or `opaque`; `transparent` is rejected                                                                        |

## Dimensions and aspect ratios

For text-to-image, either pass `size` (an integer ratio from `1:4` to `4:1`) with `resolution` (`1K` or `2K`), pass pixel dimensions in `size` (such as `2048x1152`), or pass `width` and `height` together.

* Pixel constraints: each side must be at least `768`, and `width × height` must not exceed `4,194,304` (2048×2048). Each side is rounded down to a multiple of 32.
* `width` and `height` take highest priority over `size` and `resolution`.
* Unknown fields (including `quality`, `style`, `output_format`, `response_format`, `mask_url`, `auto_aspect_ratio`, `web_grounding`) return HTTP 400. Output is always PNG.

| `size` | `1K`      | `2K`      |
| ------ | --------- | --------- |
| `1:1`  | 1024×1024 | 2048×2048 |
| `4:3`  | 1152×864  | 2336×1760 |
| `3:4`  | 864×1152  | 1760×2336 |
| `3:2`  | 1248×832  | 2496×1664 |
| `2:3`  | 832×1248  | 1664×2496 |
| `16:9` | 1344×768  | 2720×1536 |
| `9:16` | 768×1344  | 1536×2720 |
| `2:1`  | 1536×768  | 2880×1440 |
| `1:2`  | 768×1536  | 1440×2880 |
| `21:9` | 1792×768  | 3104×1312 |
| `9:21` | 768×1792  | 1312×3104 |
| `4:1`  | 3072×768  | 4096×1024 |
| `1:4`  | 768×3072  | 1024×4096 |

## Reference images

Pass 1–5 publicly accessible HTTP(S) URLs without embedded credentials in `image_urls` for single-image editing or multi-image composition. Supported inputs are JPEG, PNG, WebP, and GIF. Base64 data URIs are not accepted through SeedRouter; host images at a public URL first.

When `image_urls` is supplied, the model determines output dimensions from the reference images; `size`, `resolution`, `width`, and `height` do not affect image-to-image output dimensions.

```json
{
  "model": "mai-image-2.7",
  "prompt": "Make the bicycle blue and add a small dog sitting beside the front wheel",
  "image_urls": [
    "https://example.com/bicycle.png"
  ]
}
```

## Billing

Billing uses three token categories: text input, image input, and image output. Multiply the measured usage in each category by its live rate. Failed requests are not charged. See [live pricing](https://seedrouter.ai/models/mai-image-2-7#pricing).

## Task response and polling

An accepted request returns an asynchronous task:

```json
{"id":"task_example","model":"mai-image-2.7","status":"processing"}
```

```bash
curl https://api.seedrouter.ai/v1/tasks/task_example \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY"
```

A completed response contains the delivered PNG URL in `output.data[0].url`, its measured `size`, `output.output_format`, and `output.usage`. Poll every 5–10 seconds. Do not submit a duplicate request after a client timeout.

## Errors

HTTP errors use `{"error":{"code":integer,"message":string}}`. See the [shared error directory](https://seedrouter.ai/docs/errors) and [task lifecycle](https://seedrouter.ai/docs/api/tasks).

## Related pages

* [MAI-Image-2.7 Playground and pricing](https://seedrouter.ai/models/mai-image-2-7)
* [MAI-Image-2.7 Flash](https://seedrouter.ai/models/mai-image-2-7-flash)
