# grok-imagine (https://reapi.ai/docs/grok-imagine)

> xAI's Grok Imagine image models on reAPI at a **flat price per image**, in
> two quality tiers selected with the `quality` field (`standard` or `high`).
> Up to **10 images per request**, fourteen aspect ratios, `1k` or `2k`
> output, and single-image editing on the same endpoint. Async-first: submit
> returns a `task_id`; poll until ready. See current pricing on the
> [model page](https://reapi.ai/models/grok-imagine).

## Quick example

### cURL

    ```bash
    curl https://api.reapi.ai/v1/images/generations \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "grok-imagine",
        "prompt": "A product photo of a matte black wireless speaker on a concrete plinth, soft window light, shallow depth of field",
        "quality": "standard",
        "n": 4,
        "aspect_ratio": "1:1"
      }'
    ```

### Python

    ```python
    import requests

    resp = requests.post(
        "https://api.reapi.ai/v1/images/generations",
        headers={
            "Authorization": "Bearer YOUR_API_KEY",
            "Content-Type": "application/json",
        },
        json={
            "model": "grok-imagine",
            "prompt": "A product photo of a matte black wireless speaker on a concrete plinth, soft window light, shallow depth of field",
            "quality": "standard",
            "n": 4,
            "aspect_ratio": "1:1",
        },
        timeout=30,
    )
    print(resp.json())
    ```

### Node.js

    ```js
    const r = await fetch("https://api.reapi.ai/v1/images/generations", {
      method: "POST",
      headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        model: "grok-imagine",
        prompt:
          "A product photo of a matte black wireless speaker on a concrete plinth, soft window light, shallow depth of field",
        quality: "standard",
        n: 4,
        aspect_ratio: "1:1",
      }),
    });
    console.log(await r.json());
    ```

### Go

    ```go
    package main

    import (
        "bytes"
        "encoding/json"
        "fmt"
        "io"
        "net/http"
    )

    func main() {
        body, _ := json.Marshal(map[string]any{
            "model":        "grok-imagine",
            "prompt":       "A product photo of a matte black wireless speaker on a concrete plinth, soft window light, shallow depth of field",
            "quality":      "standard",
            "n":            4,
            "aspect_ratio": "1:1",
        })
        req, _ := http.NewRequest("POST", "https://api.reapi.ai/v1/images/generations", bytes.NewReader(body))
        req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
        req.Header.Set("Content-Type", "application/json")

        resp, _ := http.DefaultClient.Do(req)
        defer resp.Body.Close()
        out, _ := io.ReadAll(resp.Body)
        fmt.Println(string(out))
    }
    ```

The response carries a `task_id`. Poll
[`GET /api/v1/tasks/{task_id}`](/docs/api/tasks) until `status` is
`completed`, then read `result.images[].url`.

## Endpoint

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

Headers: `Authorization: Bearer YOUR_API_KEY`, `Content-Type: application/json`.
Accepts and returns JSON.

## Request body

| Field          | Type      | Required | Default    | Description                                                                                                              |
| -------------- | --------- | -------- | ---------- | ------------------------------------------------------------------------------------------------------------------------ |
| `model`        | string    | yes      | —          | Must be `grok-imagine`.                                                                                                  |
| `prompt`       | string    | yes      | —          | Image description, rendered as written. Up to 10000 characters.                                                          |
| `quality`      | string    | no       | `standard` | Quality tier: `standard` or `high`. Selects which Grok Imagine model serves the request. The **only billing dimension**. |
| `n`            | integer   | no       | `1`        | Images to return, `1`–`10`. Each delivered image is billed.                                                              |
| `aspect_ratio` | string    | no       | `auto`     | Output framing — 14 values, listed below. Does **not** change the rate.                                                  |
| `resolution`   | string    | no       | `1k`       | Pixel tier: `1k` or `2k`. Does **not** change the rate on either tier.                                                   |
| `image_urls`   | string\[] | no       | —          | One public http(s) image URL. Present ⇒ image editing (see below), billed at the same flat rate as a generation.         |

### `quality` tiers

| Value      | What it is                                                                                    |
| ---------- | --------------------------------------------------------------------------------------------- |
| `standard` | The volume tier — the lowest flat rate per image on the platform. Default.                    |
| `high`     | Spends more on each image for finer detail. Same request shape, same ratios, same batch size. |

Both tiers are Grok Imagine models from xAI. Only `quality` changes the price;
everything else is free to vary. The pricing table on the
[model page](https://reapi.ai/models/grok-imagine) lists the current rate for
each tier.

### `aspect_ratio` values

`auto`, `1:1`, `3:4`, `4:3`, `9:16`, `16:9`, `2:3`, `3:2`, `9:19.5`,
`19.5:9`, `9:20`, `20:9`, `1:2`, `2:1`.

`auto` (the default) lets the model pick the framing that suits the prompt.
Values outside this list return `400 INVALID_REQUEST`.

  Output pixels follow the ratio and the `resolution` tier — a `1:1` request at
  `1k` returns 1024×1024, a `16:9` request at `2k` returns 2816×1584. Trust
  the returned image rather than assuming a fixed size from the ratio alone.

## Image editing

Supplying `image_urls` with one public image URL switches the request to
editing on the selected tier. Describe the change in `prompt`.

```bash
curl https://api.reapi.ai/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine",
    "prompt": "Render this image as a pencil sketch with detailed shading",
    "quality": "high",
    "image_urls": ["https://example.com/photo.jpg"],
    "aspect_ratio": "1:1"
  }'
```

Reference images must be public http(s) URLs — base64 and `data:` URIs are
rejected platform-wide. This surface takes **exactly one** reference image;
multi-image compositing is available on
[grok-imagine-image-2-0](/docs/grok-imagine-image-2-0).

## Response

Submission returns the standard async envelope:

```json
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8AYYM6R03TGZ3Q2P0TZVNPX"
    }
  ]
}
```

Polled completion (`GET /api/v1/tasks/{task_id}`):

```json
{
  "code": 200,
  "data": {
    "status": "completed",
    "result": {
      "images": [
        { "url": "https://cdn.reapi.ai/..." },
        { "url": "https://cdn.reapi.ai/..." }
      ]
    }
  }
}
```

`result.images` carries one entry per delivered image, so a request with
`n: 4` returns four entries. Image URLs are valid for 24 hours from
completion — re-host the asset to your own storage if you need durable
access.

## Pricing

Grok Imagine bills a **flat rate per delivered image on each tier**,
multiplied by `n`:

* **`quality`** selects the tier and is the only dimension that moves the
  per-image rate.
* **`aspect_ratio`**, **`resolution`** and **`n`** do not change the per-image
  rate — a `2k` banner costs the same as a `1k` square on the same tier.
* **Editing** (one reference image) bills the same flat per-image rate as a
  generation.

```
credits = ceil(per_image_usd × n × 1000)
```

`1 credit = $0.001`. The rounding happens once on the aggregate, not per
image. See the [model page](https://reapi.ai/models/grok-imagine) for the
live rate of each tier.

Failed generations are refunded automatically — the reserved credits return
to your balance when a task ends in failure.

## Errors

`grok-imagine` shares the platform-wide [error envelope](/docs/api/errors).

* `prompt` missing, empty, or whitespace-only → `400 INVALID_REQUEST`.
* `prompt` longer than 10000 characters → `400 INVALID_REQUEST`.
* `quality` set to anything other than `standard` / `high` → `400 INVALID_REQUEST`.
* `n` outside `1`–`10` → `400 INVALID_REQUEST`.
* `aspect_ratio` outside its 14 values → `400 INVALID_REQUEST`.
* `resolution` set to anything other than `1k` / `2k` → `400 INVALID_REQUEST`.
* More than one entry in `image_urls`, or a non-http(s) URL → `400 INVALID_REQUEST`.
* Upstream rejection of the content → `80006 CONTENT_POLICY_VIOLATION`; the
  task fails and is refunded.

## Tips

* Use `standard` with `n` up to 10 to explore, then re-run the winning prompt
  on `high` for the final asset — the request shape is identical.
* Ask for the shape you will ship: generating `16:9` directly beats cropping
  a square, and on Grok Imagine it costs the same.
* For edits, describe the change rather than the whole scene — the reference
  image already carries the composition.

## Related

* [grok-imagine-image-2-0](/docs/grok-imagine-image-2-0) — the newer model with quality control and multi-reference editing
* [nano-banana-2-lite](/docs/nano-banana-2-lite) — another low-cost image tier
* [grok-imagine-video-1-5](/docs/grok-imagine-video-1-5) — the video sibling in the same family