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

# 视频（OpenAI 风格）

> 使用 OpenAI 标准接口 /v1/videos 进行 Veo 视频生成与任务查询。

本文档使用统一的 OpenAI 风格接口，不涉及任何上游供应商信息。你可以直接用 Bearer Token 调用 `/v1/videos` 创建任务，并用 `/v1/videos/{id}` 查询进度、`/v1/videos/{id}/content` 下载成片。

## 认证

* `Authorization: Bearer <Token>`

```bash theme={null}
export BASE_URL="https://models.rivus.cn/v1"
export TOKEN="oh-xxxxxxxxxxxxxxxx"
```

## 可用模型

* `veo-3.1-fast-generate-preview`（快速出片）
* `veo-3.1-generate-preview`（标准质量）

> 后续如有新增型号，可在“可用模型”接口或控制台查看，无需改动调用方式。

## 文生视频（JSON）

注意：`seconds` 需以字符串提交（JSON 标签为 `,string`）。

```bash theme={null}
curl -X POST "$BASE_URL/videos" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "veo-3.1-fast-generate-preview",
    "prompt": "a cinematic lion at sunset",
    "seconds": "6",
    "size": "1280x720"
  }'
```

成功时返回：

```json theme={null}
{
  "id": "video_xxx",
  "object": "video",
  "model": "veo-3.1-fast-generate-preview",
  "status": "queued",
  "progress": 0,
  "created_at": 1761234567,
  "seconds": "6",
  "size": "1280x720"
}
```

## 图生视频（multipart）

通过 `input_reference` 字段上传 1–3 张参考图（可重复多次）：

```bash theme={null}
curl -X POST "$BASE_URL/videos" \
  -H "Authorization: Bearer $TOKEN" \
  -F "model=veo-3.1-fast-generate-preview" \
  -F "prompt=Neon rain street, cinematic" \
  -F "seconds=6" \
  -F "size=1280x720" \
  -F "input_reference=@tmp/veo_refs/ref1_1280x720.jpg" \
  -F "input_reference=@tmp/veo_refs/ref2_720x1280.jpg"
```

## 查询任务

```bash theme={null}
curl "$BASE_URL/videos/{video_id}" \
  -H "Authorization: Bearer $TOKEN"
```

完成后响应会包含直链：`video_url`（或 `result.video_url`）。

## 下载视频

```bash theme={null}
curl -L "$BASE_URL/videos/{video_id}/content" \
  -H "Authorization: Bearer $TOKEN" \
  --output out.mp4
```

<Callout type="info">
  网关会统一代理视频直链，保证下载稳定性与安全性；无需关心实际存储来源。
</Callout>

## API 调试面板（可直接试用）

本页已嵌入 `POST /v1/videos` 的调试面板（见页首）。你可以：

* 选择模型与参数，发起创建请求；
* 复制返回的 `id`，再用 cURL 调用查询/下载接口；
* 若你使用 SDK，也可直接复用同样的请求体结构。

## 参数说明

* `model`：视频生成模型（必填）
* `prompt`：文本提示词（建议英文或中英混合）
* `seconds`：视频时长（秒，JSON 需以字符串提交）
* `size`：分辨率（如 `1280x720`、`720x1280`、`1920x1080`、`1080x1920`）
* `input_reference`：参考图（multipart 下可重复 1–3 次）
* `extend_from`：基于历史成片续写（部分型号/时长可能受限）

## 最佳实践

* 1080p 场景建议配合 8 秒时长；其余尺寸常用 4/6/8 秒。
* 图生视频优先提供与目标画幅一致的参考图（横版/竖版）。
* 轮询查询时使用 6–10 秒退避，避免过于频繁的请求。

## 计费

按视频时长（秒）计费。若响应无法解析到时长，可在查询时追加 `?duration=6` 明确计费秒数。


## OpenAPI

````yaml POST /v1/videos
openapi: 3.0.0
info:
  title: OpenAI Video API
  description: OpenAI Sora 视频生成 API
  version: 1.0.0
servers:
  - url: https://models.rivus.cn
    description: Rivus AI 生产环境
security:
  - BearerAuth: []
paths:
  /v1/videos:
    post:
      tags:
        - Videos
      summary: 创建视频任务
      description: 使用 OpenAI Sora 模型创建视频生成任务
      operationId: createVideo
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - model
                - prompt
              properties:
                model:
                  type: string
                  description: 模型名称
                  enum:
                    - sora-2
                    - sora-2-pro
                  example: sora-2
                prompt:
                  type: string
                  description: 视频生成的文本描述，最多 1000 个字符
                  maxLength: 1000
                  example: 百事可乐宣传片
                seconds:
                  type: integer
                  description: >-
                    视频时长（秒）。sora-2 支持 4、8、10、12、15 秒，默认 10；sora-2-pro 支持
                    4、8、12、15、25 秒，默认 15
                  enum:
                    - 4
                    - 8
                    - 10
                    - 12
                    - 15
                    - 25
                  example: 4
                size:
                  type: string
                  description: 视频分辨率
                  enum:
                    - 1280x720
                    - 1920x1080
                    - 720x1280
                    - 1080x1920
                  default: 1280x720
                  example: 720x1280
      responses:
        '200':
          description: 任务创建成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VideoObject'
              example:
                id: video_691209aab0a08198a4e78870277f7e3d0215e09cec47a737
                object: video
                created_at: 1762789802
                status: queued
                model: sora-2
                prompt: 百事可乐宣传片
                progress: 0
                seconds: '4'
                size: 720x1280
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: 认证失败
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: 请求频率超限
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    VideoObject:
      type: object
      properties:
        id:
          type: string
          description: 视频任务的唯一标识符
          example: video_691209aab0a08198a4e78870277f7e3d0215e09cec47a737
        object:
          type: string
          description: 对象类型
          enum:
            - video
          example: video
        created_at:
          type: integer
          description: 创建时间戳（Unix 时间）
          example: 1762789802
        completed_at:
          type: integer
          description: 任务完成时间戳（仅在 completed 状态下存在）
          example: 1762789891
        expires_at:
          type: integer
          description: 视频过期时间戳（仅在 completed 状态下存在）
          example: 1762793491
        model:
          type: string
          description: 使用的模型名称
          example: sora-2
        status:
          type: string
          description: 任务状态
          enum:
            - queued
            - processing
            - completed
            - failed
          example: queued
        prompt:
          type: string
          description: 生成视频的文本描述
          example: 一个无人机从海滩升空拍摄夕阳
        progress:
          type: integer
          description: 处理进度（0-100）
          minimum: 0
          maximum: 100
          example: 0
        seconds:
          type: string
          description: 视频时长（字符串格式）
          example: '10'
        size:
          type: string
          description: 视频分辨率
          example: 1280x720
        assets:
          type: array
          description: 生成的视频资源数组，仅在 completed 状态下存在（部分供应商可能不返回此字段，需通过 /content 端点下载）
          items:
            $ref: '#/components/schemas/VideoAsset'
        parent_video_id:
          type: string
          description: 父视频 ID（仅 Remix 任务返回）
          example: video_691209aab0a08198a4e78870277f7e3d0215e09cec47a737
        error:
          type: object
          description: 错误信息，仅在 failed 状态下存在
          properties:
            code:
              type: string
              example: generation_failed
            message:
              type: string
              example: 视频生成失败，请重试
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: 错误描述
              example: Invalid request parameters
            type:
              type: string
              description: 错误类型
              example: invalid_request_error
            code:
              type: string
              description: 错误代码
              example: invalid_parameters
    VideoAsset:
      type: object
      properties:
        url:
          type: string
          description: 视频文件 URL
          example: >-
            https://cdn.example.com/video_691209aab0a08198a4e78870277f7e3d0215e09cec47a737.mp4
        quality:
          type: string
          description: 视频质量/分辨率
          example: 1280x720
        duration:
          type: integer
          description: 视频时长（秒）
          example: 10
        size_bytes:
          type: integer
          description: 文件大小（字节）
          example: 5242880
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 使用 API Key 作为 Bearer Token

````