---
title: Video Generation
description: AI-powered video creation in your chat app
---

## Overview

Generate videos directly in chat using AI models. Users describe what they want and the model produces a short video clip, which is then playable inline.

## Quick Start

Install the [video tool](../tools/generate-video), then enable it in `chat.config.ts`:

```ts
ai: {
  tools: {
    video: {
      enabled: true, // Requires durable file storage
    },
  },
}
```

> **Note**
>
> Video generation requires a durable [file storage provider](../storage) for
> generated videos.

Configure the default video model:

```ts
ai: {
  tools: {
    video: {
      default: "xai/grok-imagine-video",
    },
  },
}
```

## Parameters

The tool accepts the following inputs:

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `prompt` | string | Required | Descriptive text for the video |
| `aspectRatio` | `"16:9"` \| `"9:16"` \| `"1:1"` | `"16:9"` | Output aspect ratio |
| `durationSeconds` | number (1–10) | `5` | Length of the generated video |

The LLM fills in these parameters automatically based on the user's request.

## Architecture

Follows the [Tool Part](/cookbook/tool-part) pattern:

```text
tools/chatjs/generate-video/tool.ts → tools/chatjs/generate-video/renderer.tsx
```

### Tool Output

```ts
return { videoUrl: result.url, prompt };
```

The generated video is uploaded through the configured Files SDK provider and the ChatJS file URL is returned. Supported container formats are mp4, webm, and mov, resolved from the response media type.

### UI States

| State | Shows |
| --- | --- |
| `input-available` | Pulsing placeholder + `Generating video: {prompt}` |
| `output-available` | Inline video player with controls, autoplay, loop, and mute |
| `failed` | Error message with suggestion to try a different prompt |

## Configuration

### Video Model

```ts title="chat.config.ts"
ai: {
  tools: {
    video: {
      default: "xai/grok-imagine-video",
    },
  },
}
```

### Model Selection Logic

When the tool runs, it resolves the model to use:

1. If the user's selected chat model supports video output (per the app model registry, `model.output.video`), use it.
2. Otherwise, fall back to `config.ai.tools.video.default`.

### Google Model Handling

For Google (Gemini) models, `aspectRatio` is passed in provider-specific options as well as the top-level parameter.
