> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apimart.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# MAI-Image-2.6 Image Generation

> Text-to-image, single-image editing, composition with up to 5 reference images, and web grounding. Available in high-quality and Flash versions.

## Model selection

| Model ID | Features |
| - | - |
| `mai-image-2.6` | High-quality version for quality-focused use cases |
| `mai-image-2.6-flash` | Faster, lower-cost version with slightly lower image quality |

Both models share the same capabilities and parameters and generate only 1 image per request. Refer to [model pricing](https://apimart.ai/pricing) for actual prices.

<Info>
  This endpoint is asynchronous. Retrieve the task ID from `data[0].task_id` after submission, then use [task queries](/en/api-reference/tasks/status) for results. Poll every 3–5 seconds with an overall wait timeout of 3 minutes. Stop when the status is `completed` or `failed`.
</Info>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.apimart.ai/v1/images/generations \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "mai-image-2.6",
      "prompt": "A photorealistic poster of a university campus at sunset, cinematic lighting",
      "size": "16:9",
      "resolution": "2K"
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.apimart.ai/v1/images/generations",
      headers={"Authorization": "Bearer <token>"},
      json={
          "model": "mai-image-2.6",
          "prompt": "A photorealistic poster of a university campus at sunset, cinematic lighting",
          "size": "16:9",
          "resolution": "2K"
      }
  )
  response.raise_for_status()
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api.apimart.ai/v1/images/generations", {
    method: "POST",
    headers: {
      Authorization: "Bearer <token>",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "mai-image-2.6",
      prompt: "A photorealistic poster of a university campus at sunset, cinematic lighting",
      size: "16:9",
      resolution: "2K"
    })
  });
  if (!response.ok) throw new Error(await response.text());
  console.log(await response.json());
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "code": 200,
    "data": [
      {
        "status": "submitted",
        "task_id": "task_01K..."
      }
    ]
  }
  ```
</ResponseExample>

## Request headers

<ParamField header="Authorization" type="string" required>
  Bearer authentication in the format `Bearer <token>`, where `<token>` is your APIMart API Key.
</ParamField>

## Request parameters

<ParamField body="model" type="string" required>
  Model ID: `mai-image-2.6` or `mai-image-2.6-flash`.
</ParamField>

<ParamField body="prompt" type="string" required>
  Image description or editing instructions. Supports Chinese and English, up to approximately 32,000 tokens (not characters).
</ParamField>

<ParamField body="size" type="string" default="1:1">
  Accepts an aspect ratio (such as `16:9`), pixel dimensions (such as `1536x1024`), or `auto`.

  * Aspect ratio: any integer ratio from `1:4` to `4:1`, used together with `resolution`.
  * Pixel dimensions: accepts `widthxheight`, `width*height`, or `width×height`. In this mode, `resolution` does not determine dimensions.
  * `auto`: the model selects an aspect ratio based on the prompt.

  Text-to-image only. When reference images are provided, the model determines output dimensions.
</ParamField>

<ParamField body="resolution" type="string" default="1K">
  Supports `1K` and `2K`, including lowercase. Other tiers such as `4K` are unsupported and return HTTP 400.

  For text-to-image with an aspect ratio, this parameter selects the size tier. It does not determine dimensions when exact pixels are used. It cannot set image-to-image output dimensions.
</ParamField>

<ParamField body="width" type="integer">
  Exact pixel width. Must be provided together with `height`. This pair takes precedence over `size` and `resolution` for text-to-image dimensions.

  Both width and height must be at least 768, with no more than 2,359,296 total pixels. Use multiples of 32; otherwise each output dimension is rounded down to a multiple of 32.

  This parameter does not determine image-to-image output dimensions.
</ParamField>

<ParamField body="height" type="integer">
  Exact pixel height. Must be provided together with `width` and follows the constraints above. Does not determine image-to-image output dimensions.
</ParamField>

<ParamField body="image_urls" type="string[]">
  Reference image list, up to 5 images. Omit for text-to-image; provide one for single-image editing or multiple for composition.

  Each entry supports a publicly accessible HTTP(S) image URL or a Base64 Data URL such as `data:image/png;base64,...`.

  JPEG and PNG are supported; WEBP and GIF are automatically converted to PNG. Image URLs must be publicly accessible or the task will fail.

  **Image-to-image output dimensions are determined by the model from the references**, at about 1 million pixels with a similar aspect ratio. `size`, `resolution`, `width`, and `height` cannot set these dimensions.
</ParamField>

<ParamField body="auto_aspect_ratio" type="boolean" default="false">
  Set to `true` to let the model choose an aspect ratio based on the prompt, equivalent to `size: "auto"`.
</ParamField>

<ParamField body="web_grounding" type="boolean" default="false">
  Set to `true` to retrieve real-time information before generation, useful for images involving real people, places, or events.
</ParamField>

<ParamField body="n" type="integer" default="1">
  Only `1` is supported. Submit separate tasks for multiple images. Values above 1 return HTTP 400.
</ParamField>

## Text-to-image dimensions

| Requirement | Parameters |
| - | - |
| Default square | Omit size parameters: `1:1` + `1K`, producing 1024×1024 |
| Resolution tier + aspect ratio | `size: "16:9"`, `resolution: "2K"` |
| Exact pixels | `size: "1536x1024"`, or `width: 1536`, `height: 1024` |
| Automatic aspect ratio | `size: "auto"` or `auto_aspect_ratio: true` |

Text-to-image dimension precedence: paired `width` / `height` → exact-pixel `size` → aspect-ratio `size` combined with `resolution`.

### Resolution tiers and aspect ratios

| Aspect ratio | 1K | 2K |
| - | - | - |
| 1:1 | 1024×1024 | 1536×1536 |
| 4:3 / 3:4 | 1152×864 / 864×1152 | 1760×1312 / 1312×1760 |
| 3:2 / 2:3 | 1248×832 / 832×1248 | 1856×1248 / 1248×1856 |
| 16:9 / 9:16 | 1344×768 / 768×1344 | 2048×1152 / 1152×2048 |
| 2:1 / 1:2 | 1536×768 / 768×1536 | 2144×1056 / 1056×2144 |
| 21:9 / 9:21 | 1792×768 / 768×1792 | 2336×992 / 992×2336 |
| 4:1 / 1:4 | 3072×768 / 768×3072 | 3072×768 / 768×3072 |

Dimensions are converted to multiples of 32. Since the shorter side must be at least 768, extreme aspect ratios can exceed approximately 1 million pixels even at `1K`. Billing uses the token count corresponding to the actual output pixels.

### Exact-pixel constraints

* Both width and height must be at least 768.
* Width × height must not exceed 2,359,296 (1536 × 1536).
* Each dimension is rounded down to a multiple of 32. For example, `1000x1000` produces `992x992`. Use multiples of 32 for exact dimensions.

Dimensions such as `1536x1024`, `2048x1152`, and `3072x768` are supported. `512x512` is rejected because the sides are too small; `2048x2048` exceeds the total pixel limit.

<Warning>
  The maximum applies to **total pixels**, not a 1536 limit on each side. Therefore, `2048x1152` and `3072x768` are valid, but the 4K tier is unsupported. These dimension settings apply only to text-to-image.
</Warning>

## Request examples

### Exact pixels and web grounding

```json theme={null}
{
  "model": "mai-image-2.6-flash",
  "prompt": "The Eiffel Tower at night with fireworks, travel poster style",
  "width": 2048,
  "height": 1152,
  "web_grounding": true
}
```

### Single-image editing

```json theme={null}
{
  "model": "mai-image-2.6",
  "prompt": "Make the bicycle blue and add a small dog next to it",
  "image_urls": ["https://example.com/bicycle.png"]
}
```

### Multi-image composition

```json theme={null}
{
  "model": "mai-image-2.6-flash",
  "prompt": "Combine both reference images into a clean futuristic product photo",
  "image_urls": [
    "https://example.com/first.png",
    "https://example.com/second.jpg"
  ]
}
```

Replace the example image URLs with accessible URLs.

## Unsupported parameters

`quality`, `style`, `background`, `output_format`, `response_format`, and `mask_url` are unsupported and ignored if provided. Output is always PNG. Mask-based editing is not supported.

## Submission response

<ResponseField name="code" type="integer">
  Response status code. `200` indicates success.
</ResponseField>

<ResponseField name="data" type="array">
  Task submission result.

  <Expandable title="Show task fields">
    <ResponseField name="status" type="string">
      `submitted` indicates successful submission, not completed generation.
    </ResponseField>

    <ResponseField name="task_id" type="string">
      Task ID used to query status and results.
    </ResponseField>
  </Expandable>
</ResponseField>

## Query task results

```bash theme={null}
curl --request GET \
  --url https://api.apimart.ai/v1/tasks/task_01K... \
  --header 'Authorization: Bearer <token>'
```

Example success response (the image URL is a placeholder):

```json theme={null}
{
  "code": 200,
  "data": {
    "id": "task_01K...",
    "status": "completed",
    "progress": 100,
    "result": {
      "images": [
        {
          "url": ["https://example.com/generated-image.png"]
        }
      ]
    }
  }
}
```

| Status | Action |
| - | - |
| `pending` | Queued; continue polling |
| `processing` | Processing; continue polling |
| `completed` | Success; get image links from the `data.result.images[0].url` array |
| `failed` | Failure; read `data.error.message` and stop polling. Full refund |

## Billing

Billed by actual input and output token usage. Refer to [model pricing](https://apimart.ai/pricing) for unit prices.

* Image output tokens = actual output width × height ÷ 1024. For example, 1024×1024 corresponds to 1024 tokens; 1536×1536 to 2304 tokens.
* Input tokens per reference image are approximately its width × height ÷ 1024. Text prompts also count toward input usage.
* An amount based on the tier is charged upfront, then adjusted after success to actual token usage with a refund or additional charge.
* Failed tasks receive an automatic full refund. Parameter errors rejected at submission create no task and incur no charge.

## Common errors

| HTTP | Cause and action |
| - | - |
| 400 | Unsupported `resolution`, such as `4K`; use `1K` or `2K` |
| 400 | Width or height below 768, or total pixels above 2,359,296 |
| 400 | Only `width` or `height` provided; both are required together |
| 400 | Aspect ratio outside `1:4` to `4:1`, or unrecognized `size` format |
| 400 | `n` above 1, or more than 5 reference images |

If a task fails, check image download or content safety errors. Revise the prompt or references before retrying. Editing photorealistic images involving minors may be blocked by content safety policies.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.