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

# 查詢影片

> 查詢影片任務，並在生成與結算完成後取得結果。

將 `TASK_ID` 設為[建立影片](https://docs.dgrid.ai/zh-Hant/api-reference/videos/create-video.md)回傳的 `id`，並使用相同的 Model API Key。此請求無須提供內容。 請將影片任務 ID 填入 `TASK_ID`。上傳回應的 `asset_id` 用於查詢參考素材的審核狀態。

```bash theme={null}
TASK_ID='replace-with-returned-video-task-id'
curl -sS --fail-with-body --max-time 30 \
  "$DGRID_BASE_URL/videos/$TASK_ID" \
  --header "Authorization: Bearer $DGRID_API_KEY"
```

## 任務與結算狀態

| 查詢結果 | 處理方式 |
| - | - |
| `pending`、`preparing`、`submitting`、`queued`、`running` | 繼續輪詢原任務。 |
| `billing_pending`，或 `succeeded` 但結算尚未完成 | 保留任務 ID 並繼續輪詢。 |
| `settlement_status` 為 `awaiting_balance` | 補足餘額後，再查詢原任務。 |
| `succeeded` 且 `settlement_status` 為 `settled` | 讀取 `video_url`、`billing.total` 和可用的 `usage.video_tokens`。 |
| `failed`、`cancelled`、`expired` | 停止輪詢並顯示錯誤。 |
| `submission_unknown`、`configuration_blocked` 或無法辨識的狀態 | 保留任務 ID 和錯誤詳情，並在提交替代任務前聯絡 DGrid 支援。 |

優先顯示錯誤及需查明的狀態。可先每 5 秒查詢一次，並設定本機等待上限。若停止輪詢，請保留 ID 以便之後繼續查詢。若任務已成功且結算完成，但缺少 `video_url`，請提供任務 ID 給支援團隊。

## 結算完成的回應範例

以下網址、用量及金額僅供結構示意。

```json theme={null}
{
  "id": "11111111-1111-4111-8111-111111111111",
  "status": "succeeded",
  "settlement_status": "settled",
  "video_url": "https://example.invalid/generated-video.mp4",
  "usage": {
    "video_tokens": 123456
  },
  "billing": {
    "total": "1.32097920"
  }
}
```

| 欄位 | 說明 |
| - | - |
| `id` | 影片任務 ID。 |
| `status` | 影片生成狀態。 |
| `settlement_status` | 結算狀態，須與 `status` 一併判讀。 |
| `estimated_amount` | 初始美元預估金額，以十進位字串表示。 |
| `video_url` | 結果網址。在生成與結算完成後讀取。 |
| `usage.video_tokens` | 實際影片 Token 用量，視回應提供情況而定。 |
| `billing.total` | 最終結算的美元金額。 |
| `error` | 回應中提供的錯誤詳情。 |

24 小時有效期適用於參考素材的簽名上傳網址。

## 費用與輪詢錯誤

DGrid 於受理時預留預估費用。最終金額以 `billing.total` 為準，費率請參閱 DGrid 目前的模型定價。參考影片可能影響適用費率級距和計費的輸入長度。若送審影片的輸入長度需計費，預估時會使用上傳所記錄的影片長度。影片 Token 的最終結算採用供應商回報的實際用量。

若收到 `404 video_task_not_found`，請核對任務 UUID，並使用建立任務時的 Model API Key。遇到 `429` 時，若有 `Retry-After` 請依其指示等待。遇到暫時的 `5xx` 或網路逾時，可逐步延長等待時間，限制重試次數並查詢同一筆任務。


## OpenAPI

````yaml api-reference/openapi.json GET /v1/videos/{id}
openapi: 3.1.0
info:
  title: DGrid AI Gateway API
  description: >-
    A single, unified API to access 200+ leading AI models. OpenAI-, Claude-,
    and Gemini-compatible endpoints for chat, completions, embeddings, images,
    video, audio, and moderations.
  version: 1.0.0
  contact:
    name: DGrid AI
    url: https://dgrid.ai
servers:
  - url: https://api.dgrid.ai
    description: DGrid AI Gateway
security:
  - bearerAuth: []
paths:
  /v1/videos/{id}:
    get:
      tags:
        - Videos
      summary: Retrieve video
      description: Retrieve the status and result of a video generation task.
      operationId: retrieveVideo
      parameters:
        - name: id
          in: path
          description: ID returned when creating the video task.
          required: true
          schema:
            type: string
            description: DGrid video task ID.
            format: uuid
      responses:
        '200':
          description: Current video task details.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: DGrid video task ID.
                    format: uuid
                  model:
                    type: string
                    description: Model used for the task.
                  status:
                    type: string
                    description: Video task status.
                  settlement_status:
                    type: string
                    description: Billing settlement status.
                  estimated_amount:
                    type: string
                    description: Estimated cost in USD as a decimal string.
                  created_at:
                    type: string
                    description: Task creation timestamp.
                    format: date-time
                  video_url:
                    type: string
                    description: >-
                      Video URL. Read it after the task succeeds and settlement
                      completes.
                    format: uri
                  usage:
                    type: object
                    properties:
                      video_tokens:
                        type: integer
                        description: Actual video token usage when available.
                  billing:
                    type: object
                    properties:
                      total:
                        type: string
                        description: Final settled amount in USD.
                  error:
                    description: Error details when available.
                    oneOf:
                      - type: string
                      - type: object
              example:
                id: 11111111-1111-4111-8111-111111111111
                status: succeeded
                settlement_status: settled
                video_url: https://example.invalid/generated-video.mp4
                usage:
                  video_tokens: 123456
                billing:
                  total: '1.32097920'
        '404':
          description: Video task not found.
        '429':
          description: Rate limit exceeded.
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your DGrid API key. All endpoints use `Authorization: Bearer
        <DGRID_API_KEY>`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.