概述

使用 API Key 通过 Seedance API 生成视频。API 支持文生视频和图生视频两种模式。视频生成是异步的 - 你提交任务后轮询查询结果。

接口地址

生成视频

  • 方法: POST
  • 地址: https://api.seedanceapi.dev/v1/video/generate

查询任务

  • 方法: POST
  • 地址: https://api.seedanceapi.dev/v1/video/query

认证方式

在请求头中添加 API Key:

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

生成视频请求

{
  "prompt": "一只戴着墨镜的猫在沙滩上行走,背景是棕榈树",
  "model": "seedance-pro-5s",
  "image": "https://example.com/reference-image.jpg"
}

参数说明

参数类型必填说明
promptstring是*视频描述文字
modelstring使用的模型(默认: seedance-pro-5s
imagestring否*参考图片 URL(图生视频)

*promptimage 至少需要提供一个。

支持的模型

模型分辨率时长积分消耗
seedance-lite-5s720p5秒12
seedance-lite-10s720p10秒24
seedance-pro-5s1080p5秒35
seedance-pro-10s1080p10秒70
seedance-1.5-pro-5s1080p + 音频5秒50
seedance-1.5-pro-10s1080p + 音频10秒100

生成响应

{
  "code": 0,
  "message": "ok",
  "data": {
    "task_id": "abc123-def456-789",
    "status": "pending",
    "model": "seedance-pro-5s",
    "scene": "text-to-video"
  }
}

查询任务请求

{
  "task_id": "abc123-def456-789"
}

查询响应

{
  "code": 0,
  "message": "ok",
  "data": {
    "task_id": "abc123-def456-789",
    "status": "success",
    "model": "seedance-pro-5s",
    "scene": "text-to-video",
    "videos": [
      {
        "url": "https://cdn.seedanceapi.dev/videos/abc123.mp4"
      }
    ],
    "error": null
  }
}

任务状态说明

状态说明
pending任务排队中
processing视频生成中
success生成完成
failed生成失败

使用示例

cURL - 生成视频

curl -X POST "https://api.seedanceapi.dev/v1/video/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "一只戴着墨镜的猫在沙滩上行走",
    "model": "seedance-pro-5s"
  }'

cURL - 查询任务

curl -X POST "https://api.seedanceapi.dev/v1/video/query" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "task_id": "abc123-def456-789"
  }'

Node.js

async function generateVideo() {
  // 第一步:提交视频生成任务
  const genRes = await fetch('https://api.seedanceapi.dev/v1/video/generate', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      prompt: '一只戴着墨镜的猫在沙滩上行走',
      model: 'seedance-pro-5s',
    }),
  });

  const genResult = await genRes.json();
  if (genResult.code !== 0) throw new Error(genResult.message);

  const taskId = genResult.data.task_id;
  console.log('任务已提交:', taskId);

  // 第二步:轮询查询结果
  while (true) {
    await new Promise((r) => setTimeout(r, 15000)); // 等待 15 秒

    const queryRes = await fetch('https://api.seedanceapi.dev/v1/video/query', {
      method: 'POST',
      headers: {
        Authorization: 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ task_id: taskId }),
    });

    const queryResult = await queryRes.json();
    if (queryResult.code !== 0) throw new Error(queryResult.message);

    const { status, videos, error } = queryResult.data;

    if (status === 'success') {
      console.log('视频已生成:', videos[0].url);
      return videos[0].url;
    }

    if (status === 'failed') {
      throw new Error(error || '视频生成失败');
    }

    console.log('当前状态:', status);
  }
}

Python

import requests
import time


def generate_video():
    headers = {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
    }

    # 第一步:提交视频生成任务
    gen_res = requests.post(
        'https://api.seedanceapi.dev/v1/video/generate',
        headers=headers,
        json={
            'prompt': '一只戴着墨镜的猫在沙滩上行走',
            'model': 'seedance-pro-5s',
        },
        timeout=60
    )
    gen_result = gen_res.json()
    if gen_result.get('code') != 0:
        raise Exception(gen_result.get('message'))

    task_id = gen_result['data']['task_id']
    print(f'任务已提交: {task_id}')

    # 第二步:轮询查询结果
    while True:
        time.sleep(15)  # 等待 15 秒

        query_res = requests.post(
            'https://api.seedanceapi.dev/v1/video/query',
            headers=headers,
            json={'task_id': task_id},
            timeout=60
        )
        query_result = query_res.json()
        if query_result.get('code') != 0:
            raise Exception(query_result.get('message'))

        data = query_result['data']
        status = data['status']

        if status == 'success':
            video_url = data['videos'][0]['url']
            print(f'视频已生成: {video_url}')
            return video_url

        if status == 'failed':
            raise Exception(data.get('error') or '视频生成失败')

        print(f'当前状态: {status}')


if __name__ == '__main__':
    generate_video()

错误响应

{
  "code": 400,
  "message": "Insufficient credits"
}

常见错误码:

  • 400: 请求参数错误或积分不足
  • 401: API Key 无效
  • 403: 无权访问该任务
  • 404: 任务不存在
  • 500: 服务器错误