# Grok Imagine API

> Grok Imagine — high-quality AI video generation.

- **Provider**: Grok
- **Model id**: `grok-imagine-image-to-video`
- **Modality**: video
- **Price**: 2.93–4.3 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 to receive a signed webhook on completion |

### 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. |
| 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 (default: 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://example.com/input.jpg"
    ],
    "task_id": "example",
    "index": "0",
    "prompt": "A cinematic aerial shot of a coastal town at golden hour, gentle waves rolling onto the shore, warm light, slow camera push-in.",
    "mode": "normal",
    "aspect_ratio": "2:3",
    "duration": "6",
    "resolution": "480p",
    "nsfw_checker": true
  }
}
```

### Response example

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

## 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 |
| 422 | Parameter validation failed |
| 429 | Request rate limit exceeded |
| 500 | Internal server error |
