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

# Text to Image

> GPT Image 2 Text-to-Image — Generate images from text prompts (OpenAI-compatible)

Generate images from text using GPT Image 2. Synchronous upstream; the API still exposes the standard async submit/query/webhook flow.

### Available Model

`gpt-image-2/text-to-image`

### Pricing

Billed per **resolution tier × n**. Failed tasks are not charged.

| `resolution`   | Unit price         |
| -------------- | ------------------ |
| `1k` (default) | **\$0.02 / image** |
| `2k`           | **\$0.04 / image** |
| `4k`           | **\$0.06 / image** |

Total cost = `n × unit_price(resolution)`.

<ParamField body="model" type="string" required>
  `gpt-image-2/text-to-image`
</ParamField>

<ParamField body="callBackUrl" type="string">
  Webhook callback URL.
</ParamField>

<ParamField body="input" type="object" required>
  <Expandable title="properties" defaultOpen>
    <ParamField body="prompt" type="string" required>
      Text description of the image to generate.
    </ParamField>

    <ParamField body="ratio" type="string">
      Image aspect ratio. 13 supported values:

      `1:1` / `3:2` / `2:3` / `4:3` / `3:4` / `5:4` / `4:5` / `16:9` / `9:16` / `2:1` / `1:2` / `21:9` / `9:21`

      Defaults to upstream's choice when omitted.

      <Warning>
        When `resolution = 4k`, `ratio` must be one of `16:9` / `9:16` / `2:1` / `1:2` / `21:9` / `9:21`. Other ratios at 4K exceed the upstream pixel budget and will be rejected.
      </Warning>
    </ParamField>

    <ParamField body="resolution" type="string">
      Output resolution tier. One of `1k` / `2k` / `4k`. Defaults to `1k` when omitted.

      `ratio × resolution` → actual pixels:

      | ratio  | `1k`      | `2k`      | `4k`      |
      | ------ | --------- | --------- | --------- |
      | `1:1`  | 1024×1024 | 2048×2048 | ❌         |
      | `3:2`  | 1536×1024 | 2048×1360 | ❌         |
      | `2:3`  | 1024×1536 | 1360×2048 | ❌         |
      | `4:3`  | 1024×768  | 2048×1536 | ❌         |
      | `3:4`  | 768×1024  | 1536×2048 | ❌         |
      | `5:4`  | 1280×1024 | 2560×2048 | ❌         |
      | `4:5`  | 1024×1280 | 2048×2560 | ❌         |
      | `16:9` | 1536×864  | 2048×1152 | 3840×2160 |
      | `9:16` | 864×1536  | 1152×2048 | 2160×3840 |
      | `2:1`  | 2048×1024 | 2688×1344 | 3840×1920 |
      | `1:2`  | 1024×2048 | 1344×2688 | 1920×3840 |
      | `21:9` | 2016×864  | 2688×1152 | 3840×1648 |
      | `9:21` | 864×2016  | 1152×2688 | 1648×3840 |
    </ParamField>

    <ParamField body="n" type="integer">
      Number of images to generate. Range `1-10`. Default `1`. Billed linearly: `n × unit_price(resolution)`.
    </ParamField>
  </Expandable>
</ParamField>

<RequestExample>
  ```bash Default (1K) theme={null}
  curl --request POST \
    --url https://api.maxapi.io/api/v1/task/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-image-2/text-to-image",
    "callBackUrl": "https://example.com/webhook",
    "input": {
      "prompt": "A crow running down a neon-lit street",
      "ratio": "16:9",
      "n": 1
    }
  }'
  ```

  ```bash 4K Output theme={null}
  curl --request POST \
    --url https://api.maxapi.io/api/v1/task/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-image-2/text-to-image",
    "callBackUrl": "https://example.com/webhook",
    "input": {
      "prompt": "An ancient castle under a starry sky",
      "ratio": "16:9",
      "resolution": "4k",
      "n": 1
    }
  }'
  ```

  ```bash Batch (n=4, 2K) theme={null}
  curl --request POST \
    --url https://api.maxapi.io/api/v1/task/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-image-2/text-to-image",
    "callBackUrl": "https://example.com/webhook",
    "input": {
      "prompt": "A watercolor orange tabby cat",
      "ratio": "1:1",
      "resolution": "2k",
      "n": 4
    }
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Submitted successfully theme={null}
  {
    "code": 0,
    "msg": "ok",
    "data": {
      "taskId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
    }
  }
  ```
</ResponseExample>

***

## Query Result

Retrieve the result via the [Query Task](/api-reference/query-task) endpoint or Webhook.

```json theme={null}
{
  "code": 0,
  "msg": "ok",
  "data": {
    "taskId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "status": "SUCCESS",
    "input": {
      "model": "gpt-image-2/text-to-image",
      "prompt": "A crow running down a neon-lit street"
    },
    "result": {
      "type": "image",
      "urls": ["https://cdn.maxapi.io/images/.../image-0.png"]
    }
  }
}
```

<Note>
  All result URLs are stable Max API CDN links. With `n > 1`, the array contains multiple images.
</Note>
