# Grok Imagine 2.0 API

> Grok Imagine 2.0 images by xAI from a text description, five aspect ratios.

Developer: xAI
Model key in the API: `grok_image2`

## Connect in three steps

1. [Get a key](https://api.cyhub.ai/docs/connection.md?lang=en): Create a key in the dashboard after you confirm your email. One key opens every model.
2. [Check the price](https://api.cyhub.ai/docs/generations.md?lang=en): POST /v1/price shows the cost of a run in advance, without charging you.
3. [Run a task and collect the result](https://api.cyhub.ai/docs/tasks.md?lang=en): POST /v1/tasks starts a task, GET /v1/tasks/{id} shows its status and files.

## Ready-to-use code

Replace YOUR_API_KEY with your key. The code starts a task and waits for the result. In cURL, repeat the second request with the id from the first response instead of TASK_ID until status becomes succeeded.

```bash
curl -X POST "https://api.cyhub.ai/v1/tasks" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
  "model": "grok_image2",
  "settings": {
    "prompt": "Рыжий кот спит на подоконнике, за окном вечерний город, тёплый свет лампы",
    "aspect_ratio": "3:2"
  }
}'

curl "https://api.cyhub.ai/v1/tasks/TASK_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```python
import time

import requests

API = "https://api.cyhub.ai/v1"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}

body = {
    "model": "grok_image2",
    "settings": {
        "prompt": "Рыжий кот спит на подоконнике, за окном вечерний город, тёплый свет лампы",
        "aspect_ratio": "3:2",
    },
}

response = requests.post(f"{API}/tasks", json=body, headers=HEADERS, timeout=60)
response.raise_for_status()
task = response.json()
while task["status"] in ("queued", "running"):
    time.sleep(5)
    task = requests.get(f"{API}/tasks/{task['id']}", headers=HEADERS, timeout=30).json()
print(task["status"], task["result"])
```

```javascript
const API = "https://api.cyhub.ai/v1";
const HEADERS = { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json" };

const body = {
  "model": "grok_image2",
  "settings": {
    "prompt": "Рыжий кот спит на подоконнике, за окном вечерний город, тёплый свет лампы",
    "aspect_ratio": "3:2"
  }
};

async function main() {
  let response = await fetch(`${API}/tasks`, { method: "POST", headers: HEADERS, body: JSON.stringify(body) });
  if (!response.ok) throw new Error(await response.text());
  let task = await response.json();
  while (task.status === "queued" || task.status === "running") {
    await new Promise((resolve) => setTimeout(resolve, 5000));
    response = await fetch(`${API}/tasks/${task.id}`, { headers: HEADERS });
    task = await response.json();
  }
  console.log(task.status, task.result);
}

main();
```

[Get a key](https://cyhub.ai/cabinet/keys)

## Price before the run

Prices as of 15.10.2026: from 7 ₽. POST /v1/price shows the exact price of your settings.

Send the same settings to POST /v1/price: the response shows the price of the run without charging you.

```bash
curl -X POST "https://api.cyhub.ai/v1/price" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
  "model": "grok_image2",
  "settings": {
    "prompt": "Рыжий кот спит на подоконнике, за окном вечерний город, тёплый свет лампы",
    "aspect_ratio": "3:2"
  }
}'
```

- amount_minor: the price of the run in minor units (kopecks for rubles)
- currency: the wallet currency
- available_minor: how much your balance has for new tasks right now

Price in this mode from 7 ₽.

## <a id="parameters"></a>Parameters

Model parameters go inside settings. Omitted optional fields take their default values.

### `prompt` (Required)

What to draw: who is in frame, what is around, how it is shot, the light and the mood.

- Type: String
- Minimum characters: 1
- Maximum characters: 5000

### `aspect_ratio` (Optional)

Aspect ratio: 1:1 square, 2:3 and 3:2 like a photograph, 16:9 wide frame, 9:16 vertical.

- Type: String
- Allowed values: `1:1`, `2:3`, `3:2`, `16:9`, `9:16`
- Default: `"1:1"`

Parameters not listed here are not accepted: the response is 422 unknown_setting.

> The API sets these settings itself, do not send them: `edit_button` = `false`

## <a id="input"></a>Input

- Text only: the model does not take pictures as input.

## <a id="example"></a>Request example

Send this JSON to POST /v1/tasks with your API key. To check the price first, send the same JSON to POST /v1/price.

An image from a description

```json
{
  "model": "grok_image2",
  "settings": {
    "prompt": "Рыжий кот спит на подоконнике, за окном вечерний город, тёплый свет лампы",
    "aspect_ratio": "3:2"
  }
}
```

A vertical image for Stories

```json
{
  "model": "grok_image2",
  "settings": {
    "prompt": "Девушка в жёлтом дождевике на мокрой улице ночного Токио, неоновые вывески",
    "aspect_ratio": "9:16"
  }
}
```

The price is calculated when the task is accepted, currency `RUB`.

[Complete generation example](https://api.cyhub.ai/docs/generations.md?lang=en)

## <a id="output"></a>Output

- One image per run, usually in 1-4 minutes.
- Reworking a finished picture piece by piece is only available in the bot.

| Kind | Formats | How many | Note |
|---|---|---|---|
| `image` | jpg, png | 1 |  |

A finished task as GET /v1/tasks/{id} returns it (some fields left out). The caption may sit on the task or on a single file and may be empty; the model picks the file name.

```json
{
  "id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "status": "succeeded",
  "finished_at": "2026-10-01T12:03:41+00:00",
  "result": {
    "caption": "Caption of the result: the model and its settings",
    "texts": [],
    "files_expire_at": "2026-10-08T12:03:41+00:00",
    "files_expired": false,
    "artifacts": [
      {
        "index": 0,
        "kind": "image",
        "filename": "image.jpg",
        "size": 1843200,
        "caption": "",
        "download_path": "/v1/tasks/7c9e6679-7425-40de-944b-e07fc1f90ae7/artifacts/0"
      }
    ]
  }
}
```

[How to read the result and download files](https://api.cyhub.ai/docs/tasks.md?lang=en#result)

## See also

- [Grok Imagine 2.0: features and prices](https://api.cyhub.ai/models/grok-imagine-2)
- Similar models: [GPT Image 2.5 API](https://api.cyhub.ai/en/models/gpt-image-2-5/api.md), [Nano Banana Pro API](https://api.cyhub.ai/en/models/nano-banana-pro/api.md), [Nano Banana 2 Lite API](https://api.cyhub.ai/en/models/nano-banana-2-lite/api.md), [Midjourney 8.2 API](https://api.cyhub.ai/en/models/midjourney/api.md), [Seedream 5.0 PRO API](https://api.cyhub.ai/en/models/seedream-5-pro/api.md), [Recraft API](https://api.cyhub.ai/en/models/recraft/api.md)
- [API documentation](https://api.cyhub.ai/docs.md?lang=en)
- [API errors and how to handle them](https://api.cyhub.ai/docs/errors.md?lang=en)
