# Grok Imagine Video

> xAI Grok creative video model with imaginative storytelling

- Model page: https://yir.ai/models/grok-imagine-video
- Model ID: `spacexai/grok-imagine-video`
- Billing: by the channel that ran the job; attempts the upstream did not bill are free.

## Pricing

Current public prices by channel for the same output specification; official prices are a reference. You are billed by the channel that actually runs the job, which may change on failover.

| Output specification | Channel | Public price |
|---|---|---|
| 6s · 480p | xAI (official) | $0.05 ~ $0.0503 / second |
| 6s · 480p | APIMart | $0.0102 / second |
| 6s · 480p | KIE | $0.012 / second |
| 6s · 720p | xAI (official) | $0.07 ~ $0.0703 / second |
| 6s · 720p | APIMart | $0.0191 / second |
| 6s · 720p | KIE | $0.0225 / second |
| 8s · 480p | xAI (official) | $0.0505 / second |
| 8s · 480p | KIE | $0.012 / second |
| 8s · 720p | xAI (official) | $0.0705 / second |
| 8s · 720p | KIE | $0.0225 / second |
| 10s · 480p | xAI (official) | $0.05 ~ $0.0502 / second |
| 10s · 480p | APIMart | $0.0102 / second |
| 10s · 480p | KIE | $0.012 / second |
| 10s · 720p | xAI (official) | $0.07 ~ $0.0702 / second |
| 10s · 720p | APIMart | $0.0191 / second |
| 10s · 720p | KIE | $0.0225 / second |
| 15s · 480p | xAI (official) | $0.05 ~ $0.0501 / second |
| 15s · 480p | APIMart | $0.0102 / second |
| 15s · 480p | KIE | $0.012 / second |
| 15s · 720p | xAI (official) | $0.07 ~ $0.0701 / second |
| 15s · 720p | APIMart | $0.0191 / second |
| 15s · 720p | KIE | $0.0225 / second |
| 30s · 480p | xAI (official) | $0.05 ~ $0.0501 / second |
| 30s · 480p | APIMart | $0.0102 / second |
| 30s · 480p | KIE | $0.012 / second |
| 30s · 720p | xAI (official) | $0.07 ~ $0.0701 / second |
| 30s · 720p | APIMart | $0.0191 / second |
| 30s · 720p | KIE | $0.0225 / second |

## Parameters

- Operation: `generate_video`

| Parameter | Values | Default |
|---|---|---|
| `input` | text / image / reference | text |
| `resolution` | 480p / 720p | 480p |
| `aspect_ratio` | 16:9 / 9:16 / 1:1 / 3:2 / 2:3 | 16:9 |
| `duration` | 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 / 10 / 11 / 12 / 13 / 14 / 15 / 30 | 6 |

## Integration

Pick either: the official SDK for new code, or swap the Base URL in projects already using the OpenAI protocol.

### Official SDK (TypeScript)

The SDK calls the Standard API (https://gateway.yir.ai) to submit, wait for and collect jobs; a Go SDK is also available. https://yir.ai/docs/integrations/sdk

```bash
pnpm add @yir-ai/sdk
```

```ts
import { createNodeYirClient } from "@yir-ai/sdk/server";

// Reads YIR_API_KEY from the environment by default: process.env.YIR_API_KEY
const client = createNodeYirClient();

// 1. Submit a video generation job
const job = await client.submitVideo({
  model: "spacexai/grok-imagine-video",
  input: {
    type: "text",
    prompt: "A sea turtle swims slowly over a coral reef. The camera tracks smoothly from the side as sunlight filters through clear water, casting moving patterns across its shell",
  },
  parameters: {
    duration: 6,
    resolution: "480p",
    aspect_ratio: "16:9",
    generate_audio: true,
    n: 1,
  },
});

// 2. Wait for the job to finish and deliver its result
const result = await client.waitForJob(job.id);
console.log("Delivered files:", result.result);
if (result.result && "files" in result.result) {
  for (const file of result.result.files) {
    console.log("->", file.url);
  }
}
```

### OpenAI-compatible API

OpenAI Images and Sora Videos protocols for OpenAI SDKs and gateways such as new-api; no chat. https://yir.ai/docs/integrations/openai-compatibility

- OpenAI SDK base_url: `https://gateway.yir.ai/openai/v1`
- new-api channel Base URL (channel type OpenAI): `https://gateway.yir.ai/openai`
- Model ID: `spacexai/grok-imagine-video`

```bash
curl https://gateway.yir.ai/openai/v1/videos \
  -H "Authorization: Bearer $YIR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "spacexai/grok-imagine-video",
    "prompt": "A sea turtle swims slowly over a coral reef. The camera tracks smoothly from the side as sunlight filters through clear water, casting moving patterns across its shell",
    "resolution": "480p",
    "aspect_ratio": "16:9",
    "seconds": "6"
  }'
```

## FAQ

### Does Grok Imagine Video have an official API?

Yes. xAI sells Grok Imagine Video through its own official API. At the same specification, third-party providers on Yir list it for up to 80% less (see the table above), and you call them all with one Yir API key.

## Rules

- Authenticate with Authorization: Bearer $YIR_API_KEY; keep the key in a server environment variable, never in browser code, source control, prompts or logs.
- Jobs are asynchronous: keep the Job ID, wait for a terminal state, then read the result; handle failure and cancellation.
- For safe retries, reuse the same idempotency key and request; do not blindly resubmit when the result is unknown.
- Result URLs are temporary; copy files elsewhere if you need to keep them.

## Links

- [Quickstart](https://yir.ai/docs/getting-started/quickstart)
- [API reference](https://yir.ai/docs/reference)
- [llms.txt](https://yir.ai/llms.txt)
