# Grok Imagine Image 2.0 API

> xAI's Grok Imagine 2.0 — fast, stylised image generation with up to 12 images per request.

- **Provider**: xAI
- **Model id**: `grok-imagine-image-2-text-to-image`
- **Modality**: image
- **Price**: 2.2 credits /image

## Overview

Grok Imagine Image 2.0 is called in two steps: create a generation task, then poll the task until the result is ready.

## Authentication

All requests require a Bearer Token in the request header:

```
Authorization: Bearer YOUR_API_KEY
```

## Create Task

`POST https://you.bot/api/v1/generate`

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| modelId | string | Yes | Model id: `grok-imagine-image-2-text-to-image` |
| input | object | Yes | Input parameters object (see below) |
| callbackUrl | string | No | https URL to receive a signed webhook on completion |

### input object parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| prompt | string | Yes | What to generate. Required, up to 10,000 characters. Max 10000 characters. (default: An editorial product poster for a ceramic pour-over kettle, bold headline type, soft studio light, generous negative space) |
| size | string | No | Framing of the generated image. (options: 1:1 | 2:3 | 3:2 | 3:4 | 4:3 | 9:16 | 16:9) (default: 1:1) |
| n | string | No | How many images to generate. Each delivered image is charged. (options: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12) (default: 1) |

### Request example

```json
{
  "modelId": "grok-imagine-image-2-text-to-image",
  "input": {
    "prompt": "A photorealistic portrait of a red fox in a snowy forest, soft morning light, shallow depth of field, 85mm.",
    "size": "1:1",
    "n": "1"
  }
}
```

### Response example

```json
{
  "taskId": "281e5b0…f39b9",
  "creditsCharged": 2.2
}
```

## Query Task

`GET https://you.bot/api/v1/task/{taskId}?model=grok-imagine-image-2-text-to-image`

When `state` is `success`, the output is in `resultUrls`: `{ "state": "success", "resultUrls": [ ... ] }`. (Text models return inline in the create response.)

## Error Codes

| Code | Description |
|------|-------------|
| 200 | Request successful |
| 400 | Invalid request parameters |
| 401 | Authentication failed, check API Key |
| 402 | Insufficient account balance |
| 422 | Parameter validation failed |
| 429 | Request rate limit exceeded |
| 500 | Internal server error |
