---
title: 獲取影片內容
description: 下載或流式讀取已完成任務的影片檔案。
icon: download
openapi: GET /v1/videos/{task_id}/content
---

任務狀態為 `completed` 後，使用內容介面讀取生成影片。介面可能直接返回影片流，也可能跟隨安全代理讀取最終影片。

<ParamField path="task_id" type="string" required>
  已完成的影片任務 ID。
</ParamField>

## 下載到檔案

```bash
curl -L https://api.heizhu.lol/v1/videos/task_xxxxxxxxxx/content \
  -H "Authorization: Bearer $BLACKPIG_API_KEY" \
  --output result.mp4
```

`-L` 用於跟隨可能出現的重定向。內容介面同樣需要 Bearer Token。

## JavaScript

```javascript
const response = await fetch(
  `https://api.heizhu.lol/v1/videos/${taskId}/content`,
  {
    headers: {
      Authorization: `Bearer ${process.env.BLACKPIG_API_KEY}`,
    },
  },
);

if (!response.ok) {
  throw new Error(await response.text());
}

const video = Buffer.from(await response.arrayBuffer());
await fs.promises.writeFile('result.mp4', video);
```

## 使用建議

- 僅在任務狀態為 `completed` 後請求內容。
- 獲取成功後，將結果儲存到你自己的物件儲存。
- 不要在前端暴露平臺 Token；由你的服務端獲取後再提供受控下載。
- 對較大檔案使用流式寫入，避免全部載入記憶體。

