# Grok Imagine API

> Grok Imagine — high-quality AI video generation.

- **Provider**: Grok
- **Model id**: `grok-imagine-image-to-video`
- **Modality**: video
- **Price**: 1.53–2.86 credits /sec

## Overview

Grok Imagine 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-to-video` |
| 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 |
|-----------|------|----------|-------------|
| image_urls | string[] | No | Provide one external image URL as a reference for video generation (only one image is supported). This is one of two image input options — you can either upload an external image or specify a task_id + index from a Grok-generated image below. Do not provide both image_urls and task_id at the same time.In your prompt, reference an uploaded image by typing @image(n) followed by a space (for example: @image1 a sunset over the ocean). (image URL) |
| task_id | string | No | Enter the task_id of an image previously generated with the Grok model on you.bot. Use it together with the index below to select a specific image from that generation. When using this method, do not provide image_urls. Unlike external images, this method supports Spicy mode. Max 100 characters. |
| index | number | No | When using a task_id, specify which image to use (Grok generates 6 images per task). This parameter only works with task_id and is ignored if image_urls is used(0-based). (range 0-5) (default: 0) |
| prompt | string | No | The text prompt describing the desired video motion Max 5000 characters. (example: Slow cinematic push-in with gentle ambient motion, soft light shifting across the frame, subtle parallax and a shallow, dreamlike depth of field.) |
| mode | string | No | Note: When generating videos using external image inputs, Spicy mode is not supported and will automatically switch to Normal. (options: fun \| normal \| spicy) (default: normal) |
| aspect_ratio | string | No | The aspect ratio of the video. This parameter is invalid if it is a single image. (options: 2:3 \| 3:2 \| 1:1 \| 16:9 \| 9:16) (default: 2:3) |
| duration | number | No | The duration of the generated video in seconds (range 6-30) (default: 6) |
| resolution | string | No | Resolution of the generated video (options: 480p \| 720p) (default: 480p) |
| nsfw_checker | boolean | No | A configurable parameter. Defaults to true in the Playground. (true/false) (default: true) |

### Request example

```json
{
  "modelId": "grok-imagine-image-to-video",
  "input": {
    "image_urls": [
      "https://you.bot/examples/grok-imagine-text-to-image.jpg"
    ],
    "task_id": "example",
    "index": 0,
    "prompt": "Slow cinematic push-in with gentle ambient motion, soft light shifting across the frame, subtle parallax and a shallow, dreamlike depth of field.",
    "mode": "normal",
    "aspect_ratio": "2:3",
    "duration": 6,
    "resolution": "480p",
    "nsfw_checker": true
  }
}
```

### Response example

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

## Query Task

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

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 |
