> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gravitex.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Download Video

## Introduction

The download video API is used to retrieve completed video file data. **Note: This API is only supported for Sora 2 models**. For other models (Veo, Ali Wanxiang, Doubao Seedance), the video URL is directly included in the query task API response after the task succeeds, and no additional download step is required.

## Authentication

<ParamField header="Authorization" type="string" required>
  Bearer Token, e.g. `Bearer sk-xxxxxxxxxx`
</ParamField>

## Query Parameters

<ParamField query="id" type="string" required>
  Video ID, which is the `task_id` returned by the query task API
</ParamField>

## Usage Example

```bash theme={null}
curl -X GET "https://api.gravitex.ai/v1/video/generations/download?id=video_69095b4ce0048190893a01510c0c98b0" \
  -H "Authorization: Bearer sk-xxxxxxxxxx"
```

## Response Example

```json theme={null}
{
  "success": true,
  "generation_id": "video_69095b4ce0048190893a01510c0c98b0",
  "task_id": "video_69095b4ce0048190893a01510c0c98b0",
  "format": "mp4",
  "size": 15728640,
  "base64": "AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAB...",
  "data_url": "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAB..."
}
```

## Response Field Description

| Field           | Type    | Description                                                                 |
| --------------- | ------- | --------------------------------------------------------------------------- |
| `success`       | boolean | Success status                                                              |
| `generation_id` | string  | Generation ID (same as videoId)                                             |
| `task_id`       | string  | Task ID                                                                     |
| `format`        | string  | Video format (fixed as `"mp4"`)                                             |
| `size`          | number  | Video file size (bytes)                                                     |
| `base64`        | string  | Base64 encoded video data                                                   |
| `data_url`      | string  | Data URL format video data, can be used directly in frontend `<video>` tags |

## Usage Instructions

### Frontend Usage with data\_url

The `data_url` field can be used directly in HTML `<video>` tags:

```html theme={null}
<video src="data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAB..." controls></video>
```

### Download and Save File

Use the `base64` field to save the video as a file:

#### JavaScript Example

```javascript theme={null}
// Get base64 data from response
const response = await fetch('https://api.gravitex.ai/v1/video/generations/download?id=video_xxx', {
  headers: {
    'Authorization': 'Bearer sk-xxxxxxxxxx'
  }
});
const data = await response.json();

// Convert base64 to Blob
const binaryString = atob(data.base64);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
  bytes[i] = binaryString.charCodeAt(i);
}
const blob = new Blob([bytes], { type: 'video/mp4' });

// Create download link
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'video.mp4';
a.click();
URL.revokeObjectURL(url);
```

#### Python Example

```python theme={null}
import requests
import base64

def download_video(video_id, api_key):
    """Download video and save as file"""
    url = f"https://api.gravitex.ai/v1/video/generations/download?id={video_id}"
    headers = {"Authorization": f"Bearer {api_key}"}
    
    response = requests.get(url, headers=headers)
    data = response.json()
    
    if data.get("success"):
        # Decode base64 data
        video_data = base64.b64decode(data["base64"])
        
        # Save as file
        with open("video.mp4", "wb") as f:
            f.write(video_data)
        
        print(f"✅ Video saved: video.mp4 (size: {data['size']} bytes)")
        return True
    else:
        print("❌ Download failed")
        return False
```

## Complete Workflow Example (Sora 2)

1. **Submit Video Generation Task**

   ```bash theme={null}
   curl -X POST "https://api.gravitex.ai/v1/video/generations" \
     -H "Authorization: Bearer sk-xxxxxxxxxx" \
     -H "Content-Type: application/json" \
     -d '{
       "model": "sora-2",
       "prompt": "A cute little cat playing in the garden",
       "seconds": "4",
       "size": "720x1280"
     }'
   ```

   Response:

   ```json theme={null}
   {
     "task_id": "video_69095b4ce0048190893a01510c0c98b0",
     "status": "submitted",
     "format": "mp4"
   }
   ```

2. **Query Task Status** (poll until success)

   ```bash theme={null}
   curl -X GET "https://api.gravitex.ai/v1/video/generations/video_69095b4ce0048190893a01510c0c98b0" \
     -H "Authorization: Bearer sk-xxxxxxxxxx"
   ```

   When status is `succeeded`, proceed to next step.

3. **Download Video File**
   ```bash theme={null}
   curl -X GET "https://api.gravitex.ai/v1/video/generations/download?id=video_69095b4ce0048190893a01510c0c98b0" \
     -H "Authorization: Bearer sk-xxxxxxxxxx"
   ```

## Related APIs

<Columns cols={2}>
  <Card title="Submit Video Task" icon="upload" href="/en/api-reference/endpoint/submit-video-task">
    Submit video generation task
  </Card>

  <Card title="Query Video Task" icon="search" href="/en/api-reference/endpoint/query-video-task">
    Query video generation task status and results
  </Card>
</Columns>
