> ## 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.

# 建立影片

> 建立非同步影片生成任務，並保存任務 ID 以便輪詢。

使用正式環境的 DGrid **Model API Key**，確認帳號有模型存取權限且餘額足以支付預估費用。以下參數適用於 Seedance 2.5。憑證設定和完整流程請參閱[影片生成指南](https://docs.dgrid.ai/zh-Hant/ai-gateway/video-generation.md)。

## Seedance 2.5 請求參數

| 參數 | 說明 |
| - | - |
| `model` | `bytedance/seedance-2.5`。 |
| `content` | 文字提示詞，以及選用的參考圖片或影片。 |
| `duration` | 正整數，單位為秒。單次生成上限為 30 秒，輸入組合仍須符合支援規格。 |
| `resolution` | 輸出解析度，範例使用 `720p`。可用規格依模型及渠道而定。 |
| `ratio` | 選用的長寬比，例如 `16:9`。 |
| `generate_audio` | 選用布林值，控制是否生成音訊。 |
| `watermark` | 選用布林值，控制浮水印。 |
| `seed` | 選用的整數種子值。 |

將以下範例儲存為 `request.json`。

```json theme={null}
{
  "model": "bytedance/seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "清晨的海邊，鏡頭緩慢向前推進，浪花輕拍礁石，畫面自然平穩。"
    }
  ],
  "duration": 5,
  "resolution": "720p",
  "ratio": "16:9",
  "generate_audio": false,
  "watermark": false
}
```

以 `application/json` 傳送請求內容，並使用 Bearer 權杖驗證。每筆新任務都要使用專屬的 `Idempotency-Key`。送出請求可能產生費用。

```bash theme={null}
export DGRID_IDEMPOTENCY_KEY="$(uuidgen)"

curl -sS --fail-with-body --max-time 30 \
  "$DGRID_BASE_URL/videos" \
  --header "Authorization: Bearer $DGRID_API_KEY" \
  --header "Idempotency-Key: $DGRID_IDEMPOTENCY_KEY" \
  --header 'Content-Type: application/json' \
  --data-binary @request.json
```

HTTP `202` 表示 DGrid 已受理任務並預留預估費用。請保存 `id` 以便[查詢任務](https://docs.dgrid.ai/zh-Hant/api-reference/videos/retrieve-video.md)。以下回應使用示意數值。

```json theme={null}
{
  "id": "11111111-1111-4111-8111-111111111111",
  "model": "bytedance/seedance-2.5",
  "status": "pending",
  "settlement_status": "reserved",
  "estimated_amount": "1.15560000",
  "created_at": "2026-11-30T08:00:00Z"
}
```

## 引用參考素材

使用 BytePlus Seedance 渠道時，可在 `content` 陣列的文字提示詞旁加入媒體項目。請使用上傳回傳的完整 HTTPS 網址，或提供伺服器可存取的 HTTPS 網址。外部參考影片須使用支援 HTTP Range 且可讀取影片長度的 MP4 直連網址。

```json theme={null}
{
  "model": "bytedance/seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "參考圖片中的場景和影片中的運鏡，生成一段雨後的城市街景。"
    },
    {
      "type": "image_url",
      "role": "reference_image",
      "image_url": {
        "url": "<IMAGE_UPLOAD_URL>"
      }
    },
    {
      "type": "video_url",
      "role": "reference_video",
      "video_url": {
        "url": "<VIDEO_UPLOAD_URL>"
      }
    }
  ],
  "duration": 5,
  "resolution": "720p",
  "ratio": "16:9"
}
```

同一使用者透過 DGrid 送審的素材達到 `Active` 後，可將 `asset://<IMAGE_ASSET_ID>` 填入 `image_url.url`，或將 `asset://<VIDEO_ASSET_ID>` 填入 `video_url.url`。DGrid 會在預留費用前及送出上游生成請求前確認官方狀態。即使簽名上傳網址過期，仍為 `Active` 的素材也可引用。素材仍須符合模型輸入規格與內容要求。詳情請參閱[上傳參考素材](https://docs.dgrid.ai/zh-Hant/api-reference/videos/upload-reference-asset.md)。

## 冪等與錯誤處理

如果建立請求逾時或暫時回傳 `503`，且尚未取得任務 ID，請用同一組 API Key、冪等鍵和請求內容重試。變更請求內容（含簽名網址）可能造成衝突。若受理結果仍不確定，請先查明或恢復原請求，再建立新任務。若已取得任務 ID，請直接查詢原任務。

請先檢查 HTTP 狀態。錯誤詳細資訊可能是 `error` 字串或 `error.code` 欄位。閘道錯誤可能傳回其他格式。

| HTTP 狀態 | 錯誤或情況 | 處理方式 |
| - | - | - |
| `400` | `invalid_video_request` | 檢查 JSON、媒體項目、影片長度及解析度。 |
| `401` | `unauthorized` | 檢查正式環境的 Model API Key 及 Bearer 標頭。 |
| `403` | `video_route_unavailable` | 確認模型及渠道存取權限。 |
| `403` | `balance_insufficient` | 請求未受理。補足餘額後用新的冪等鍵提交。 |
| `409` | `idempotency_conflict` | 確認該冪等鍵對應的原始請求內容。 |
| `409` | `video_asset_not_active` | 查詢審核狀態，等待 `Active`。若為 `Failed`，請查明原因。 |
| `422` | `video_asset_incompatible` | 檢查素材類型、所屬使用者及渠道。 |
| `422` | `input_duration_unavailable` | 確認影片長度可讀取，且外部網址支援 HTTP Range 請求。 |
| `429` | 速率限制 | 若有 `Retry-After`，依其指示等待並保留冪等鍵。 |
| `503` 或逾時 | 暫時故障或受理結果不確定 | 使用相同的憑證、冪等鍵及請求內容重試。 |


## OpenAPI

````yaml api-reference/openapi.json POST /v1/videos
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:
    post:
      tags:
        - Videos
      summary: Create video
      description: >-
        Submit an asynchronous video generation task. This request may incur
        charges.
      operationId: createVideo
      parameters:
        - name: Idempotency-Key
          in: header
          description: >-
            Use a unique key for a new task. Reuse that key with the same
            request body if you retry.
          required: false
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - content
                - duration
                - resolution
              properties:
                model:
                  type: string
                  description: >-
                    Video model ID. The documented request format applies to
                    Seedance 2.5.
                  example: bytedance/seedance-2.5
                content:
                  type: array
                  description: Text prompt and optional reference media.
                  items:
                    oneOf:
                      - type: object
                        required:
                          - type
                          - text
                        properties:
                          type:
                            type: string
                            const: text
                          text:
                            type: string
                            description: Text prompt.
                      - type: object
                        required:
                          - type
                          - role
                          - image_url
                        properties:
                          type:
                            type: string
                            const: image_url
                          role:
                            type: string
                            const: reference_image
                          image_url:
                            type: object
                            required:
                              - url
                            properties:
                              url:
                                type: string
                                description: >-
                                  HTTPS URL or reviewed image asset URI on the
                                  BytePlus Seedance channel.
                      - type: object
                        required:
                          - type
                          - role
                          - video_url
                        properties:
                          type:
                            type: string
                            const: video_url
                          role:
                            type: string
                            const: reference_video
                          video_url:
                            type: object
                            required:
                              - url
                            properties:
                              url:
                                type: string
                                description: >-
                                  HTTPS URL or reviewed video asset URI on the
                                  BytePlus Seedance channel.
                duration:
                  type: integer
                  description: >-
                    Duration in seconds. The maximum depends on the supported
                    input combination.
                  minimum: 1
                  maximum: 30
                  example: 5
                resolution:
                  type: string
                  description: >-
                    Output resolution. Available settings depend on the model
                    and channel.
                  example: 720p
                ratio:
                  type: string
                  description: Output aspect ratio.
                  example: '16:9'
                generate_audio:
                  type: boolean
                  description: Whether to generate audio.
                watermark:
                  type: boolean
                  description: Whether to include a watermark.
                seed:
                  type: integer
                  description: Seed value.
            example:
              model: bytedance/seedance-2.5
              content:
                - type: text
                  text: >-
                    The camera slowly moves forward along the coast at dawn as
                    waves gently lap against the rocks. Keep the motion smooth
                    and natural.
              duration: 5
              resolution: 720p
              ratio: '16:9'
              generate_audio: false
              watermark: false
      responses:
        '202':
          description: Video task accepted.
          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
              example:
                id: 11111111-1111-4111-8111-111111111111
                model: bytedance/seedance-2.5
                status: pending
                settlement_status: reserved
                estimated_amount: '1.15560000'
                created_at: '2026-11-30T08:00:00Z'
        '400':
          description: Invalid video request.
        '401':
          description: Unauthorized.
        '403':
          description: Model route unavailable or insufficient balance.
        '409':
          description: Idempotency conflict or reference asset is not active.
        '422':
          description: Incompatible asset or unreadable input duration.
        '429':
          description: Rate limit exceeded.
        '503':
          description: Temporary service failure.
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.