# 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 we POST the finished task to. Signed with `X-Webhook-Signature` once you create a webhook signing key in Dashboard → Settings |

### input object parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| prompt | string | Yes | What to generate. Required, up to 10,000 characters. Max 4000 characters. (example: Ultra-photorealistic avant-garde fashion editorial of an original futuristic dragon, square 1:1. A sleek black cyberpunk dragon styled like a high-fashion… — full value in the request example) |
| 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": "Ultra-photorealistic avant-garde fashion editorial of an original futuristic dragon, square 1:1.\n\nA sleek black cyberpunk dragon styled like a high-fashion icon, wearing elegant asymmetrical couture, flowing black fabric, sculptural chrome accessories, glossy leather details and futuristic jewelry. Sophisticated, rebellious, strange and effortlessly cool — not bulky, not military, not generic fantasy.\n\nThe dragon stares directly into the camera with a sharp, confident, slightly arrogant expression. Head lowered slightly, eyes locked on the lens. Elegant S-curve neck, body angled diagonally, one wing dramatically raised, the other partially folded, tail sweeping through the frame. A slim glowing chrome crystal is held between its teeth.\n\nBackground: clean vivid golden-yellow studio backdrop.\n\nAdd minimal bright-red geometric shapes and diagonal lines arranged around the dragon in a sophisticated triangular composition.\n\nHigh-end luxury fashion photography, large-format camera, 50mm lens, dramatic studio lighting, realistic shadows, authentic fabric and chrome reflections, detailed reptilian skin, individual scales, natural imperfections, subtle film grain.\n\nYellow + red + black dominant color palette. Bold, graphic, premium, unconventional, iconic.\n\nThe final image must look like a real luxury fashion campaign photographed in a professional studio, not CGI or a videogame render.\n\nMinimal editorial text: “NO ORDINARY BEAST”.\n\nNo logos, watermark, copyrighted characters, extra limbs, duplicated wings, malformed anatomy, bulky armor or generic cyberpunk design.",
    "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 |
| 403 | IP not allowed for this key, or the key is restricted to other models |
| 404 | Task not found, or it has expired |
| 409 | Duplicate request — an identical submit arrived moments ago. Nothing was charged; retry is safe |
| 413 | Payload too large — see the character and file-size limits for this model |
| 429 | Rate limit exceeded — retry after the Retry-After header |
| 500 | Internal server error |
| 504 | Upstream timed out — nothing was delivered; retry is safe |
