Skip to main content
GET
https://console.mixroute.io
/
v1
/
video
/
generations
/
download
curl --request GET \
  --url 'https://console.mixroute.io/v1/video/generations/download?id=video_xxx' \
  --header 'Authorization: Bearer sk-xxxxxxxxxx'
{
  "success": true,
  "generation_id": "video_xxx",
  "task_id": "video_xxx",
  "format": "mp4",
  "size": 15728640,
  "base64": "AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDE...",
  "data_url": "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDE..."
}

簡介

下載影片端點用於取得已完成的影片檔案資料。
此端點僅支援 Sora 2 模型。其他模型(Veo、阿里萬相、豆包 Seedance)在任務成功後,影片 URL 會直接包含在查詢任務回應中,無需額外下載步驟。

認證方式

Bearer Token,例如 Bearer sk-xxxxxxxxxx

查詢參數

id
string
required
影片 ID,即查詢任務端點返回的 task_id

cURL 範例

curl -X GET "https://console.mixroute.io/v1/video/generations/download?id=video_69095b4ce0048190893a01510c0c98b0" \
  -H "Authorization: Bearer sk-xxxxxxxxxx"

回應範例

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

回應欄位說明

欄位類型說明
successboolean請求是否成功
generation_idstring生成 ID(與 videoId 相同)
task_idstring任務 ID
formatstring影片格式(固定為 "mp4"
sizenumber影片檔案大小(位元組)
base64stringBase64 編碼的影片資料
data_urlstringData URL 格式的影片資料,可直接用於前端 <video> 標籤

使用說明

前端使用 data_url

data_url 欄位可以直接用於 HTML <video> 標籤:
<video src="data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAB..." controls></video>

下載儲存檔案

JavaScript 範例

// 從回應中取得 base64 資料
const response = await fetch('https://console.mixroute.io/v1/video/generations/download?id=video_xxx', {
  headers: {
    'Authorization': 'Bearer sk-xxxxxxxxxx'
  }
});
const data = await response.json();

// 將 base64 轉換為 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' });

// 建立下載連結
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'video.mp4';
a.click();
URL.revokeObjectURL(url);

Python 範例

import requests
import base64

def download_video(video_id, api_key):
    """下載影片並儲存為檔案"""
    url = f"https://console.mixroute.io/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"):
        # 解碼 base64 資料
        video_data = base64.b64decode(data["base64"])

        # 儲存為檔案
        with open("video.mp4", "wb") as f:
            f.write(video_data)

        print(f"✅ 影片已儲存:video.mp4(大小:{data['size']} 位元組)")
        return True
    else:
        print("❌ 下載失敗")
        return False

完整流程範例(Sora 2)

1. 提交影片生成任務

curl -X POST "https://console.mixroute.io/v1/video/generations" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sora-2",
    "prompt": "一隻可愛的小貓在花園裡玩耍",
    "seconds": "4",
    "size": "720x1280"
  }'
回應:
{
  "task_id": "video_69095b4ce0048190893a01510c0c98b0",
  "status": "submitted",
  "format": "mp4"
}

2. 查詢任務狀態(輪詢直到成功)

curl -X GET "https://console.mixroute.io/v1/video/generations/video_69095b4ce0048190893a01510c0c98b0" \
  -H "Authorization: Bearer sk-xxxxxxxxxx"
當狀態為 succeeded 時,繼續下一步。

3. 下載影片檔案

curl -X GET "https://console.mixroute.io/v1/video/generations/download?id=video_69095b4ce0048190893a01510c0c98b0" \
  -H "Authorization: Bearer sk-xxxxxxxxxx"

注意事項

  • 下載端點返回 Base64 編碼的影片資料,適合在前端直接顯示或儲存
  • 對於大型檔案,建議使用串流下載或直接 URL 下載
  • 影片格式固定為 MP4
curl --request GET \
  --url 'https://console.mixroute.io/v1/video/generations/download?id=video_xxx' \
  --header 'Authorization: Bearer sk-xxxxxxxxxx'
{
  "success": true,
  "generation_id": "video_xxx",
  "task_id": "video_xxx",
  "format": "mp4",
  "size": 15728640,
  "base64": "AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDE...",
  "data_url": "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDE..."
}