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

# 创建视频 · Gemini API

> 使用 Gemini API 格式提交 Seedance 视频任务，查看示例、输入限制和完整参数。

使用 Gemini API 的长任务格式调用 Seedance。查询使用 GET，成功结果位于 `response.generateVideoResponse.generatedSamples`。

如果客户端使用 Vertex AI 路径，请改看 [Vertex AI 接口](/cn/api/video-vertex)。

## 接入配置

服务地址为 `https://api.aiohub.org`，使用 AIOHub API 令牌鉴权。把 `<AIOHUB_API_KEY>` 替换为完整的 `sk-` 令牌，并确认其分组可访问所选 Seedance 模型。

## 请求示例

```bash theme={"system"}
curl "https://api.aiohub.org/v1beta/models/doubao-seedance-2-5-260628:predictLongRunning" \
  -H "Authorization: Bearer <AIOHUB_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "instances": [{
      "prompt": "A blue ceramic cup on a wooden table in daylight."
    }],
    "parameters": {
      "durationSeconds": 4,
      "aspectRatio": "16:9",
      "resolution": "720p",
      "generateAudio": true,
      "sampleCount": 1
    }
  }'
```

返回的关键字段如下。保存完整 `name`，包括模型路径和 `operations/`，不要只保存最后一段 ID。

```json theme={"system"}
{
  "name": "models/doubao-seedance-2-5-260628/operations/task_example",
  "done": false
}
```

拿到任务标识后，转到 [查询任务](/cn/api/video-gemini-get)。

## 输入与参数

未指定参数时，默认 5 秒、720p、`adaptive` 比例并生成音频。首尾帧与参考图是两种输入方式，不能在同一个 `instances[0]` 中混用。

图片对象示例：

```json theme={"system"}
{"bytesBase64Encoded": "<BASE64_IMAGE>", "mimeType": "image/png"}
```

模型上限见 [视频模型与计费](/cn/api/video-models)。不支持任意 `gs://` 输入、视频扩展或全部 Veo 参数。需要参考音频、参考视频或视频编辑时，选择 [Ark / Seedance](/cn/api/video-ark)。

<Accordion title="SDK 完整示例">
  安装 `google-genai` 并在运行环境中设置 `AIOHUB_API_KEY`。这里使用 Gemini API 模式，Base URL 不包含 `/v1beta`，版本通过 `api_version` 指定。

  ```python Python theme={"system"}
  import os
  import time
  from google import genai
  from google.genai import types

  client = genai.Client(
      api_key=os.environ["AIOHUB_API_KEY"],
      http_options=types.HttpOptions(base_url="https://api.aiohub.org", api_version="v1beta"),
  )
  op = client.models.generate_videos(
      model="doubao-seedance-2-0-260128-libtv",
      source=types.GenerateVideosSource(prompt="木桌上的蓝色陶瓷杯，自然光。"),
      config=types.GenerateVideosConfig(
          number_of_videos=1, duration_seconds=4, aspect_ratio="16:9", resolution="720p"
      ),
  )
  while not op.done:
      time.sleep(15)
      op = client.operations.get(op)
  if op.error:
      raise RuntimeError(str(op.error))
  video = op.response.generated_videos[0].video
  with open("video.mp4", "wb") as f:
      f.write(client.files.download(file=video))
  ```
</Accordion>

<Note>创建请求超时且未拿到任务标识时，先检查 [用量日志](https://api.aiohub.org/console/log)，避免重复生成和扣费。400 错误需要先修正参数；401 错误请检查令牌。模型权限和额度见 [鉴权](/cn/api/authentication)。</Note>


## OpenAPI

````yaml openapi/relay.json POST /v1beta/models/{model}:predictLongRunning
openapi: 3.0.1
info:
  title: AIOHub API
  description: AIOHub 公开 API
  version: 1.0.0
servers:
  - url: https://api.aiohub.org
security:
  - BearerAuth: []
tags:
  - name: 获取模型列表
  - name: OpenAI Chat
  - name: OpenAI Responses
  - name: 图片生成
  - name: OpenAI 图像
  - name: 视频生成
  - name: Claude Messages
  - name: Gemini API
  - name: OpenAI Embeddings
  - name: 文本补全
  - name: OpenAI 音频
  - name: Realtime API
paths:
  /v1beta/models/{model}:predictLongRunning:
    post:
      tags:
        - 视频生成
      summary: 创建 Gemini 视频任务
      description: |
        本页描述 Seedance 的 Gemini 视频格式，模型范围见 [模型与计费](/cn/api/video-models)。

        创建成功返回 name 和 done: false。保存完整 name，每 10 到 15 秒查询一次。HTTP 200 不代表视频生成完成。
      operationId: createSeedanceGeminiVideo
      parameters:
        - name: model
          in: path
          required: true
          description: 完整 Seedance 模型名。
          schema:
            type: string
            example: doubao-seedance-2-5-260628
          example: doubao-seedance-2-5-260628
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SeedanceGoogleVideoRequest'
            examples:
              text:
                summary: 文生视频
                value:
                  instances:
                    - prompt: A blue ceramic cup on a wooden table in daylight.
                  parameters:
                    durationSeconds: 4
                    aspectRatio: '16:9'
                    resolution: 720p
                    generateAudio: true
                    sampleCount: 1
      responses:
        '200':
          description: 任务已受理。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SeedanceGeminiOperation'
              example:
                name: models/doubao-seedance-2-5-260628/operations/task_example
                done: false
        '400':
          description: 字段、类型或模型能力不匹配。根据 code 和 message 修正后重试。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SeedanceTaskError'
        '401':
          description: API 令牌缺失或无效。
        '429':
          description: 请求过多或容量已满，等待后重试。
        '503':
          description: 模型在所选分组不可用，或服务暂时不可用。
      security:
        - BearerAuth: []
components:
  schemas:
    SeedanceGoogleVideoRequest:
      type: object
      properties:
        instances:
          type: array
          minItems: 1
          maxItems: 1
          description: 只提交一个实例。文本生成需 prompt；图生视频可指定 image。
          items:
            type: object
            properties:
              prompt:
                type: string
                description: 提示词。纯文本生成时必填。
              image:
                $ref: '#/components/schemas/SeedanceGoogleImage'
              lastFrame:
                $ref: '#/components/schemas/SeedanceGoogleImage'
              referenceImages:
                type: array
                minItems: 1
                maxItems: 30
                items:
                  $ref: '#/components/schemas/SeedanceGoogleReferenceImage'
                description: 2.5 最多 30 张，2.0 系列最多 9 张；不能与 image、lastFrame 混用。
        parameters:
          type: object
          properties:
            durationSeconds:
              type: integer
              minimum: 4
              maximum: 30
              default: 5
              description: 整数秒。2.5 为 4 到 30，2.0 系列为 4 到 15。
            aspectRatio:
              type: string
              description: 默认 adaptive。Seedance 2.5 首尾帧输入只能使用 adaptive。
              enum:
                - adaptive
                - '16:9'
                - '4:3'
                - '1:1'
                - '3:4'
                - '9:16'
                - '21:9'
              default: adaptive
            resolution:
              type: string
              description: 取值依模型。4k 仅用于 2.0 标准版，1080p 不适用于 fast/mini。
              enum:
                - 480p
                - 720p
                - 1080p
                - 4k
              default: 720p
            generateAudio:
              type: boolean
              default: true
              description: 是否生成音频。
            sampleCount:
              type: integer
              enum:
                - 1
              default: 1
              description: 每个任务只生成一个视频。
            numberOfVideos:
              type: integer
              enum:
                - 1
              description: sampleCount 的别名；指定时必须为 1。
      required:
        - instances
      description: >-
        本页参数范围针对 Seedance。lastFrame 必须与 image
        一起使用；参考图不可与首尾帧混用。不能传入视频扩展、mask、seed、negativePrompt 等未列出的控制参数。
    SeedanceGeminiOperation:
      type: object
      properties:
        name:
          type: string
          description: 完整 operation name。保存原值用于后续查询。
        done:
          type: boolean
          description: false 表示等待；true 表示已结束，但可能是失败，须检查 error。
        response:
          type: object
          properties:
            '@type':
              type: string
              description: 响应类型。
            generateVideoResponse:
              type: object
              properties:
                generatedSamples:
                  type: array
                  items:
                    type: object
                    properties:
                      video:
                        type: object
                        properties:
                          uri:
                            type: string
                            description: 成功后返回的完整 HTTPS 文件下载地址；下载需要 API 令牌。
                            format: uri
                        required:
                          - uri
                    required:
                      - video
        error:
          type: object
          properties:
            message:
              type: string
              description: 生成失败原因。
          required:
            - message
      required:
        - name
        - done
    SeedanceTaskError:
      type: object
      description: 视频任务接口的错误响应。
      properties:
        code:
          type: string
          description: 错误码
          example: invalid_duration
        message:
          type: string
          description: 错误信息
          example: duration must be between 4 and 30 seconds for this model
    SeedanceGoogleImage:
      type: object
      properties:
        bytesBase64Encoded:
          type: string
          description: 图片文件的 base64 内容，不带 data URL 前缀。
        mimeType:
          type: string
          description: 图片 MIME 类型，例如 image/png 或 image/jpeg。
          example: image/png
      required:
        - bytesBase64Encoded
        - mimeType
    SeedanceGoogleReferenceImage:
      type: object
      properties:
        image:
          $ref: '#/components/schemas/SeedanceGoogleImage'
        referenceType:
          type: string
          description: 使用 asset。不能与首尾帧输入混用。
          enum:
            - asset
          default: asset
      required:
        - image
        - referenceType
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API key (sk-xxx)

````

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