跳到文档内容
十方十方MAAS开发者文档进入控制台 →

开发者文档 / API 接口

Seedance 视频生成 API

文本、首尾帧与多素材生成,支持视频编辑和延长。

POST/v1/video-generations

Bearer API Key · JSON · HTTP 202

概览

请求使用 Seedance 官方字段:必填 model 与 content。文本和素材按顺序放入 content 数组。旧版 prompt、references、mode、first_frame_url 等顶层字段已移除。

调用示例

Bash / macOS / Linux;Windows 可使用 Git Bash。

# 先按“鉴权与通用约定”设置环境变量
: "${MASS_API_KEY:?请先设置 MASS_API_KEY}"
: "${MASS_IDEMPOTENCY_KEY:?请设置本次业务请求的幂等键;重试时保持不变}"
MASS_BASE_URL="${MASS_BASE_URL:-https://api.vizen.cc}"

curl --silent --show-error --fail-with-body --max-time 120 \
  -X POST "${MASS_BASE_URL%/}/v1/video-generations" \
  -H "Authorization: Bearer $MASS_API_KEY" \
  -H "Idempotency-Key: $MASS_IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "model": "doubao-seedance-2-5-260628",
  "content": [
    {
      "type": "text",
      "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
    }
  ],
  "resolution": "720p",
  "duration": 5,
  "ratio": "16:9"
}
JSON

Python 3.10+,仅使用标准库。保存为 example.py,运行 python example.py。

import json
import os
import urllib.error
import urllib.parse
import urllib.request

base_url = os.environ.get("MASS_BASE_URL", "https://api.vizen.cc").rstrip("/")
api_key = os.environ["MASS_API_KEY"]
path = "/v1/video-generations"
headers = {"Authorization": "Bearer " + api_key}
headers["Idempotency-Key"] = os.environ["MASS_IDEMPOTENCY_KEY"]
payload = json.loads(r'''{
  "model": "doubao-seedance-2-5-260628",
  "content": [
    {
      "type": "text",
      "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
    }
  ],
  "resolution": "720p",
  "duration": 5,
  "ratio": "16:9"
}''')
headers["Content-Type"] = "application/json"
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
request = urllib.request.Request(
    base_url + path, data=body, headers=headers, method="POST"
)
try:
    with urllib.request.urlopen(request, timeout=120) as response:
        result = json.load(response)
        print(json.dumps(result, ensure_ascii=False, indent=2))
except urllib.error.HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))
    raise SystemExit(1)
except urllib.error.URLError as error:
    # 创建请求出现网络异常时,保留原幂等键;不要生成新键后盲目重试。
    print("请求未能确认:", error.reason)
    raise SystemExit(1)

JDK 17+,仅使用标准库。保存为 UTF-8 的 Example.java;执行 javac -encoding UTF-8 Example.java,再执行 java Example。

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class Example {
    static String requireEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) {
            throw new IllegalArgumentException("请设置环境变量 " + name);
        }
        return value;
    }

    public static void main(String[] args) throws Exception {
        String base = System.getenv().getOrDefault("MASS_BASE_URL", "https://api.vizen.cc");
        base = base.replaceAll("/+$", "");
        String path = "/v1/video-generations";
        String body = """
            {
              "model": "doubao-seedance-2-5-260628",
              "content": [
                {
                  "type": "text",
                  "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
                }
              ],
              "resolution": "720p",
              "duration": 5,
              "ratio": "16:9"
            }
            """;
        HttpRequest request = HttpRequest.newBuilder(URI.create(base + path))
            .timeout(Duration.ofSeconds(120))
            .header("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
            .header("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20)).build();
        // 网络异常会抛出异常;重试创建请求时保留相同幂等键和参数。
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        System.out.println(response.body());
        if (response.statusCode() >= 400) {
            throw new IllegalStateException("HTTP " + response.statusCode());
        }
    }
}

Go 1.20+,仅使用标准库。保存为 main.go,运行 go run main.go。

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requireEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("请设置环境变量 " + name) }
    return value
}

func main() {
    base := os.Getenv("MASS_BASE_URL")
    if base == "" { base = "https://api.vizen.cc" }
    base = strings.TrimRight(base, "/")
    path := "/v1/video-generations"
    body := `{
  "model": "doubao-seedance-2-5-260628",
  "content": [
    {
      "type": "text",
      "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
    }
  ],
  "resolution": "720p",
  "duration": 5,
  "ratio": "16:9"
}`
    req, err := http.NewRequest("POST", base + path, strings.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
    req.Header.Set("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 120 * time.Second}
    resp, err := client.Do(req)
    // 网络异常不代表创建失败;重试时保留原幂等键和参数。
    if err != nil { panic(err) }
    defer resp.Body.Close()
    data, err := io.ReadAll(resp.Body)
    if err != nil { panic(err) }
    fmt.Println(string(data))
    if resp.StatusCode >= 400 { panic(fmt.Sprintf("HTTP %d", resp.StatusCode)) }
}

模型

model官方分辨率时长范围参考图片 / 视频 / 音频
doubao-seedance-2-5-260628480p / 720p / 1080p4~30 秒,或 -130 / 10 / 10
doubao-seedance-2-0-260128480p / 720p / 1080p / 4k4~15 秒,或 -19 / 3 / 3
doubao-seedance-2-0-fast-260128480p / 720p4~15 秒,或 -19 / 3 / 3
doubao-seedance-2-0-mini-260615480p / 720p4~15 秒,或 -19 / 3 / 3

使用官方模型 ID;不接受旧版简写或其他账户的 Endpoint ID。分辨率遵循各模型官方范围,账户授权可进一步缩小范围;不支持 2k。resolution 省略为 720p,ratio 省略为 adaptive。2.5 的 duration 默认 -1;2.0 系列未填写时由模型决定。智能时长估价按模型时长上限预留,完成后按实际用量结算。

请求参数

modelstring必填

官方模型名称与版本;账户需开通对应模型

doubao-seedance-2-5-260628 / doubao-seedance-2-0-260128 / doubao-seedance-2-0-fast-260128 / doubao-seedance-2-0-mini-260615

默认值:— · 示例:"doubao-seedance-2-5-260628"

contentarray<object>必填

官方内容数组:text、image_url、video_url、audio_url

最少项数 1

默认值:— · 示例:[{"type": "text", "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"}]

resolutionstring可选

官方模型支持的输出分辨率;账户授权可进一步缩小范围

480p / 720p / 1080p / 4k

默认值:720p · 示例:"720p"

ratiostring可选

16:9 / 4:3 / 1:1 / 3:4 / 9:16 / 21:9 / adaptive

默认值:adaptive · 示例:"16:9"

durationinteger | null可选

2.5 默认 -1,支持 4~30 秒;2.0 系列支持 4~15 秒或 -1

默认值:2.5 为 -1;2.0 系列省略时由模型决定 · 示例:5

generate_audioboolean可选

默认值:true

watermarkboolean可选

默认值:false

output_formatstring | null可选

仅 2.5 支持,默认 mp4

mp4 / mov

默认值:mp4

omni_reference_task_typestring | null可选

仅 2.5 全模态参考任务支持,省略按 auto 处理

auto / reference / edit / extend

默认值:null

return_last_frameboolean可选

接受此官方参数,但当前服务不提供尾帧输出

默认值:false

callback_urlstring | null可选

任务终态通知地址;通知体与查询响应一致

默认值:null

execution_expires_afterinteger可选

最小值 3600;最大值 259200

默认值:172800

priorityinteger可选

生成执行优先级,0~9

最小值 0;最大值 9

默认值:0

safety_identifierstring | null可选

终端用户固定英文标识,建议使用哈希值

最长字符数 64

默认值:null

toolsarray<object>可选

默认值:[]

priority 传入生成服务,平台受理和客户并发限制仍然有效。callback_url 由平台发送终态通知;execution_expires_after 用于生成任务超时配置。当前接入的是 2.x 模型,官方仅供 1.0 使用的 frames、camera_fixed、seed、service_tier 以及样片参数不支持。

content 数组项

文本

typestring必填

text

默认值:—

textstring必填

文本提示词;保持原始文字和内容顺序

最短字符数 1

默认值:—

图片

typestring必填

image_url

默认值:—

image_urlobject必填

默认值:—

rolestring | null可选

first_frame / last_frame / reference_image

默认值:null

视频

typestring必填

video_url

默认值:—

video_urlobject必填

默认值:—

rolestring | null可选

reference_video

默认值:null

音频

typestring必填

audio_url

默认值:—

audio_urlobject必填

默认值:—

rolestring | null可选

reference_audio

默认值:null

素材地址

urlstring必填

公网 HTTP/HTTPS URL、图片/音频 data URL,或 asset://素材ID

默认值:—

图片使用 image_url.url,视频使用 video_url.url,音频使用 audio_url.url。支持公网 HTTP/HTTPS 地址及 asset://素材ID;图片和音频也可直接在 url 中填完整 Base64 data URL,视频不支持 Base64。素材地址在排队和执行期间应持续可读。asset 必须可由服务账户访问,无法访问时任务会失败。

图片支持 JPEG、PNG、WebP、BMP、TIFF、GIF、HEIC、HEIF,单张小于 30 MB;音频支持 MP3/WAV,单个不超过 15 MB;视频支持 MP4/MOV,单个不超过 200 MB。请求体上限 64 MiB。文件的实际格式、尺寸、时长和内容还会在执行时校验。

首帧 role 为 first_frame(单张首帧可省略 role),尾帧为 last_frame;两张图时 role 必填,且必须有首帧。参考素材使用 reference_image、reference_video、reference_audio。首尾帧与全模态参考不可混用。2.5 的首尾帧比例必须为 adaptive;2.0 系列可指定比例。

2.5 最多 50 个参考素材,视频、音频各累计不超过 30 秒;2.0 系列最多 15 个,各累计不超过 15 秒。仅 2.5 可单独使用音频参考。

编辑与延长

2.5 使用 omni_reference_task_type 指定 auto、reference、edit、extend;省略时由模型结合提示词判断。edit / extend 必须有 reference_video 且 ratio=adaptive;edit 的 duration 必须为 -1,待编辑视频为 4~30 秒。2.0 系列通过提示词表达编辑和延长,不传此字段。

tools 数组项

typestring必填

工具类型;当前支持 web_search

web_search

默认值:—

各模式完整示例

首尾帧生成

Bash / macOS / Linux;Windows 可使用 Git Bash。

# 先按“鉴权与通用约定”设置环境变量
: "${MASS_API_KEY:?请先设置 MASS_API_KEY}"
: "${MASS_IDEMPOTENCY_KEY:?请设置本次业务请求的幂等键;重试时保持不变}"
MASS_BASE_URL="${MASS_BASE_URL:-https://api.vizen.cc}"

curl --silent --show-error --fail-with-body --max-time 120 \
  -X POST "${MASS_BASE_URL%/}/v1/video-generations" \
  -H "Authorization: Bearer $MASS_API_KEY" \
  -H "Idempotency-Key: $MASS_IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "model": "doubao-seedance-2-5-260628",
  "duration": 6,
  "content": [
    {
      "type": "text",
      "text": "从清晨自然过渡到夜晚"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/first.png"
      },
      "role": "first_frame"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/last.png"
      },
      "role": "last_frame"
    }
  ]
}
JSON

Python 3.10+,仅使用标准库。保存为 example.py,运行 python example.py。

import json
import os
import urllib.error
import urllib.parse
import urllib.request

base_url = os.environ.get("MASS_BASE_URL", "https://api.vizen.cc").rstrip("/")
api_key = os.environ["MASS_API_KEY"]
path = "/v1/video-generations"
headers = {"Authorization": "Bearer " + api_key}
headers["Idempotency-Key"] = os.environ["MASS_IDEMPOTENCY_KEY"]
payload = json.loads(r'''{
  "model": "doubao-seedance-2-5-260628",
  "duration": 6,
  "content": [
    {
      "type": "text",
      "text": "从清晨自然过渡到夜晚"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/first.png"
      },
      "role": "first_frame"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/last.png"
      },
      "role": "last_frame"
    }
  ]
}''')
headers["Content-Type"] = "application/json"
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
request = urllib.request.Request(
    base_url + path, data=body, headers=headers, method="POST"
)
try:
    with urllib.request.urlopen(request, timeout=120) as response:
        result = json.load(response)
        print(json.dumps(result, ensure_ascii=False, indent=2))
except urllib.error.HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))
    raise SystemExit(1)
except urllib.error.URLError as error:
    # 创建请求出现网络异常时,保留原幂等键;不要生成新键后盲目重试。
    print("请求未能确认:", error.reason)
    raise SystemExit(1)

JDK 17+,仅使用标准库。保存为 UTF-8 的 Example.java;执行 javac -encoding UTF-8 Example.java,再执行 java Example。

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class Example {
    static String requireEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) {
            throw new IllegalArgumentException("请设置环境变量 " + name);
        }
        return value;
    }

    public static void main(String[] args) throws Exception {
        String base = System.getenv().getOrDefault("MASS_BASE_URL", "https://api.vizen.cc");
        base = base.replaceAll("/+$", "");
        String path = "/v1/video-generations";
        String body = """
            {
              "model": "doubao-seedance-2-5-260628",
              "duration": 6,
              "content": [
                {
                  "type": "text",
                  "text": "从清晨自然过渡到夜晚"
                },
                {
                  "type": "image_url",
                  "image_url": {
                    "url": "https://your-domain.example/first.png"
                  },
                  "role": "first_frame"
                },
                {
                  "type": "image_url",
                  "image_url": {
                    "url": "https://your-domain.example/last.png"
                  },
                  "role": "last_frame"
                }
              ]
            }
            """;
        HttpRequest request = HttpRequest.newBuilder(URI.create(base + path))
            .timeout(Duration.ofSeconds(120))
            .header("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
            .header("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20)).build();
        // 网络异常会抛出异常;重试创建请求时保留相同幂等键和参数。
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        System.out.println(response.body());
        if (response.statusCode() >= 400) {
            throw new IllegalStateException("HTTP " + response.statusCode());
        }
    }
}

Go 1.20+,仅使用标准库。保存为 main.go,运行 go run main.go。

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requireEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("请设置环境变量 " + name) }
    return value
}

func main() {
    base := os.Getenv("MASS_BASE_URL")
    if base == "" { base = "https://api.vizen.cc" }
    base = strings.TrimRight(base, "/")
    path := "/v1/video-generations"
    body := `{
  "model": "doubao-seedance-2-5-260628",
  "duration": 6,
  "content": [
    {
      "type": "text",
      "text": "从清晨自然过渡到夜晚"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/first.png"
      },
      "role": "first_frame"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/last.png"
      },
      "role": "last_frame"
    }
  ]
}`
    req, err := http.NewRequest("POST", base + path, strings.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
    req.Header.Set("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 120 * time.Second}
    resp, err := client.Do(req)
    // 网络异常不代表创建失败;重试时保留原幂等键和参数。
    if err != nil { panic(err) }
    defer resp.Body.Close()
    data, err := io.ReadAll(resp.Body)
    if err != nil { panic(err) }
    fmt.Println(string(data))
    if resp.StatusCode >= 400 { panic(fmt.Sprintf("HTTP %d", resp.StatusCode)) }
}

多素材参考生成

Bash / macOS / Linux;Windows 可使用 Git Bash。

# 先按“鉴权与通用约定”设置环境变量
: "${MASS_API_KEY:?请先设置 MASS_API_KEY}"
: "${MASS_IDEMPOTENCY_KEY:?请设置本次业务请求的幂等键;重试时保持不变}"
MASS_BASE_URL="${MASS_BASE_URL:-https://api.vizen.cc}"

curl --silent --show-error --fail-with-body --max-time 120 \
  -X POST "${MASS_BASE_URL%/}/v1/video-generations" \
  -H "Authorization: Bearer $MASS_API_KEY" \
  -H "Idempotency-Key: $MASS_IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "model": "doubao-seedance-2-5-260628",
  "duration": 8,
  "omni_reference_task_type": "reference",
  "content": [
    {
      "type": "text",
      "text": "保持角色造型,按照音乐节奏生成连贯镜头"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/character.webp"
      },
      "role": "reference_image"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/motion.mp4"
      },
      "role": "reference_video"
    },
    {
      "type": "audio_url",
      "audio_url": {
        "url": "https://your-domain.example/music.mp3"
      },
      "role": "reference_audio"
    }
  ]
}
JSON

Python 3.10+,仅使用标准库。保存为 example.py,运行 python example.py。

import json
import os
import urllib.error
import urllib.parse
import urllib.request

base_url = os.environ.get("MASS_BASE_URL", "https://api.vizen.cc").rstrip("/")
api_key = os.environ["MASS_API_KEY"]
path = "/v1/video-generations"
headers = {"Authorization": "Bearer " + api_key}
headers["Idempotency-Key"] = os.environ["MASS_IDEMPOTENCY_KEY"]
payload = json.loads(r'''{
  "model": "doubao-seedance-2-5-260628",
  "duration": 8,
  "omni_reference_task_type": "reference",
  "content": [
    {
      "type": "text",
      "text": "保持角色造型,按照音乐节奏生成连贯镜头"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/character.webp"
      },
      "role": "reference_image"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/motion.mp4"
      },
      "role": "reference_video"
    },
    {
      "type": "audio_url",
      "audio_url": {
        "url": "https://your-domain.example/music.mp3"
      },
      "role": "reference_audio"
    }
  ]
}''')
headers["Content-Type"] = "application/json"
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
request = urllib.request.Request(
    base_url + path, data=body, headers=headers, method="POST"
)
try:
    with urllib.request.urlopen(request, timeout=120) as response:
        result = json.load(response)
        print(json.dumps(result, ensure_ascii=False, indent=2))
except urllib.error.HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))
    raise SystemExit(1)
except urllib.error.URLError as error:
    # 创建请求出现网络异常时,保留原幂等键;不要生成新键后盲目重试。
    print("请求未能确认:", error.reason)
    raise SystemExit(1)

JDK 17+,仅使用标准库。保存为 UTF-8 的 Example.java;执行 javac -encoding UTF-8 Example.java,再执行 java Example。

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class Example {
    static String requireEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) {
            throw new IllegalArgumentException("请设置环境变量 " + name);
        }
        return value;
    }

    public static void main(String[] args) throws Exception {
        String base = System.getenv().getOrDefault("MASS_BASE_URL", "https://api.vizen.cc");
        base = base.replaceAll("/+$", "");
        String path = "/v1/video-generations";
        String body = """
            {
              "model": "doubao-seedance-2-5-260628",
              "duration": 8,
              "omni_reference_task_type": "reference",
              "content": [
                {
                  "type": "text",
                  "text": "保持角色造型,按照音乐节奏生成连贯镜头"
                },
                {
                  "type": "image_url",
                  "image_url": {
                    "url": "https://your-domain.example/character.webp"
                  },
                  "role": "reference_image"
                },
                {
                  "type": "video_url",
                  "video_url": {
                    "url": "https://your-domain.example/motion.mp4"
                  },
                  "role": "reference_video"
                },
                {
                  "type": "audio_url",
                  "audio_url": {
                    "url": "https://your-domain.example/music.mp3"
                  },
                  "role": "reference_audio"
                }
              ]
            }
            """;
        HttpRequest request = HttpRequest.newBuilder(URI.create(base + path))
            .timeout(Duration.ofSeconds(120))
            .header("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
            .header("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20)).build();
        // 网络异常会抛出异常;重试创建请求时保留相同幂等键和参数。
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        System.out.println(response.body());
        if (response.statusCode() >= 400) {
            throw new IllegalStateException("HTTP " + response.statusCode());
        }
    }
}

Go 1.20+,仅使用标准库。保存为 main.go,运行 go run main.go。

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requireEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("请设置环境变量 " + name) }
    return value
}

func main() {
    base := os.Getenv("MASS_BASE_URL")
    if base == "" { base = "https://api.vizen.cc" }
    base = strings.TrimRight(base, "/")
    path := "/v1/video-generations"
    body := `{
  "model": "doubao-seedance-2-5-260628",
  "duration": 8,
  "omni_reference_task_type": "reference",
  "content": [
    {
      "type": "text",
      "text": "保持角色造型,按照音乐节奏生成连贯镜头"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://your-domain.example/character.webp"
      },
      "role": "reference_image"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/motion.mp4"
      },
      "role": "reference_video"
    },
    {
      "type": "audio_url",
      "audio_url": {
        "url": "https://your-domain.example/music.mp3"
      },
      "role": "reference_audio"
    }
  ]
}`
    req, err := http.NewRequest("POST", base + path, strings.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
    req.Header.Set("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 120 * time.Second}
    resp, err := client.Do(req)
    // 网络异常不代表创建失败;重试时保留原幂等键和参数。
    if err != nil { panic(err) }
    defer resp.Body.Close()
    data, err := io.ReadAll(resp.Body)
    if err != nil { panic(err) }
    fmt.Println(string(data))
    if resp.StatusCode >= 400 { panic(fmt.Sprintf("HTTP %d", resp.StatusCode)) }
}

视频编辑

Bash / macOS / Linux;Windows 可使用 Git Bash。

# 先按“鉴权与通用约定”设置环境变量
: "${MASS_API_KEY:?请先设置 MASS_API_KEY}"
: "${MASS_IDEMPOTENCY_KEY:?请设置本次业务请求的幂等键;重试时保持不变}"
MASS_BASE_URL="${MASS_BASE_URL:-https://api.vizen.cc}"

curl --silent --show-error --fail-with-body --max-time 120 \
  -X POST "${MASS_BASE_URL%/}/v1/video-generations" \
  -H "Authorization: Bearer $MASS_API_KEY" \
  -H "Idempotency-Key: $MASS_IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "model": "doubao-seedance-2-5-260628",
  "omni_reference_task_type": "edit",
  "duration": -1,
  "ratio": "adaptive",
  "content": [
    {
      "type": "text",
      "text": "将视频的天空改成晚霞,保持原有镜头节奏"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/source.mp4"
      },
      "role": "reference_video"
    }
  ]
}
JSON

Python 3.10+,仅使用标准库。保存为 example.py,运行 python example.py。

import json
import os
import urllib.error
import urllib.parse
import urllib.request

base_url = os.environ.get("MASS_BASE_URL", "https://api.vizen.cc").rstrip("/")
api_key = os.environ["MASS_API_KEY"]
path = "/v1/video-generations"
headers = {"Authorization": "Bearer " + api_key}
headers["Idempotency-Key"] = os.environ["MASS_IDEMPOTENCY_KEY"]
payload = json.loads(r'''{
  "model": "doubao-seedance-2-5-260628",
  "omni_reference_task_type": "edit",
  "duration": -1,
  "ratio": "adaptive",
  "content": [
    {
      "type": "text",
      "text": "将视频的天空改成晚霞,保持原有镜头节奏"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/source.mp4"
      },
      "role": "reference_video"
    }
  ]
}''')
headers["Content-Type"] = "application/json"
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
request = urllib.request.Request(
    base_url + path, data=body, headers=headers, method="POST"
)
try:
    with urllib.request.urlopen(request, timeout=120) as response:
        result = json.load(response)
        print(json.dumps(result, ensure_ascii=False, indent=2))
except urllib.error.HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))
    raise SystemExit(1)
except urllib.error.URLError as error:
    # 创建请求出现网络异常时,保留原幂等键;不要生成新键后盲目重试。
    print("请求未能确认:", error.reason)
    raise SystemExit(1)

JDK 17+,仅使用标准库。保存为 UTF-8 的 Example.java;执行 javac -encoding UTF-8 Example.java,再执行 java Example。

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class Example {
    static String requireEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) {
            throw new IllegalArgumentException("请设置环境变量 " + name);
        }
        return value;
    }

    public static void main(String[] args) throws Exception {
        String base = System.getenv().getOrDefault("MASS_BASE_URL", "https://api.vizen.cc");
        base = base.replaceAll("/+$", "");
        String path = "/v1/video-generations";
        String body = """
            {
              "model": "doubao-seedance-2-5-260628",
              "omni_reference_task_type": "edit",
              "duration": -1,
              "ratio": "adaptive",
              "content": [
                {
                  "type": "text",
                  "text": "将视频的天空改成晚霞,保持原有镜头节奏"
                },
                {
                  "type": "video_url",
                  "video_url": {
                    "url": "https://your-domain.example/source.mp4"
                  },
                  "role": "reference_video"
                }
              ]
            }
            """;
        HttpRequest request = HttpRequest.newBuilder(URI.create(base + path))
            .timeout(Duration.ofSeconds(120))
            .header("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
            .header("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20)).build();
        // 网络异常会抛出异常;重试创建请求时保留相同幂等键和参数。
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        System.out.println(response.body());
        if (response.statusCode() >= 400) {
            throw new IllegalStateException("HTTP " + response.statusCode());
        }
    }
}

Go 1.20+,仅使用标准库。保存为 main.go,运行 go run main.go。

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requireEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("请设置环境变量 " + name) }
    return value
}

func main() {
    base := os.Getenv("MASS_BASE_URL")
    if base == "" { base = "https://api.vizen.cc" }
    base = strings.TrimRight(base, "/")
    path := "/v1/video-generations"
    body := `{
  "model": "doubao-seedance-2-5-260628",
  "omni_reference_task_type": "edit",
  "duration": -1,
  "ratio": "adaptive",
  "content": [
    {
      "type": "text",
      "text": "将视频的天空改成晚霞,保持原有镜头节奏"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/source.mp4"
      },
      "role": "reference_video"
    }
  ]
}`
    req, err := http.NewRequest("POST", base + path, strings.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
    req.Header.Set("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 120 * time.Second}
    resp, err := client.Do(req)
    // 网络异常不代表创建失败;重试时保留原幂等键和参数。
    if err != nil { panic(err) }
    defer resp.Body.Close()
    data, err := io.ReadAll(resp.Body)
    if err != nil { panic(err) }
    fmt.Println(string(data))
    if resp.StatusCode >= 400 { panic(fmt.Sprintf("HTTP %d", resp.StatusCode)) }
}

视频延长

Bash / macOS / Linux;Windows 可使用 Git Bash。

# 先按“鉴权与通用约定”设置环境变量
: "${MASS_API_KEY:?请先设置 MASS_API_KEY}"
: "${MASS_IDEMPOTENCY_KEY:?请设置本次业务请求的幂等键;重试时保持不变}"
MASS_BASE_URL="${MASS_BASE_URL:-https://api.vizen.cc}"

curl --silent --show-error --fail-with-body --max-time 120 \
  -X POST "${MASS_BASE_URL%/}/v1/video-generations" \
  -H "Authorization: Bearer $MASS_API_KEY" \
  -H "Idempotency-Key: $MASS_IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "model": "doubao-seedance-2-5-260628",
  "omni_reference_task_type": "extend",
  "duration": 8,
  "output_format": "mov",
  "content": [
    {
      "type": "text",
      "text": "向后延长视频,人物继续向前走,保持原有光线"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/source.mp4"
      },
      "role": "reference_video"
    }
  ]
}
JSON

Python 3.10+,仅使用标准库。保存为 example.py,运行 python example.py。

import json
import os
import urllib.error
import urllib.parse
import urllib.request

base_url = os.environ.get("MASS_BASE_URL", "https://api.vizen.cc").rstrip("/")
api_key = os.environ["MASS_API_KEY"]
path = "/v1/video-generations"
headers = {"Authorization": "Bearer " + api_key}
headers["Idempotency-Key"] = os.environ["MASS_IDEMPOTENCY_KEY"]
payload = json.loads(r'''{
  "model": "doubao-seedance-2-5-260628",
  "omni_reference_task_type": "extend",
  "duration": 8,
  "output_format": "mov",
  "content": [
    {
      "type": "text",
      "text": "向后延长视频,人物继续向前走,保持原有光线"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/source.mp4"
      },
      "role": "reference_video"
    }
  ]
}''')
headers["Content-Type"] = "application/json"
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
request = urllib.request.Request(
    base_url + path, data=body, headers=headers, method="POST"
)
try:
    with urllib.request.urlopen(request, timeout=120) as response:
        result = json.load(response)
        print(json.dumps(result, ensure_ascii=False, indent=2))
except urllib.error.HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))
    raise SystemExit(1)
except urllib.error.URLError as error:
    # 创建请求出现网络异常时,保留原幂等键;不要生成新键后盲目重试。
    print("请求未能确认:", error.reason)
    raise SystemExit(1)

JDK 17+,仅使用标准库。保存为 UTF-8 的 Example.java;执行 javac -encoding UTF-8 Example.java,再执行 java Example。

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class Example {
    static String requireEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) {
            throw new IllegalArgumentException("请设置环境变量 " + name);
        }
        return value;
    }

    public static void main(String[] args) throws Exception {
        String base = System.getenv().getOrDefault("MASS_BASE_URL", "https://api.vizen.cc");
        base = base.replaceAll("/+$", "");
        String path = "/v1/video-generations";
        String body = """
            {
              "model": "doubao-seedance-2-5-260628",
              "omni_reference_task_type": "extend",
              "duration": 8,
              "output_format": "mov",
              "content": [
                {
                  "type": "text",
                  "text": "向后延长视频,人物继续向前走,保持原有光线"
                },
                {
                  "type": "video_url",
                  "video_url": {
                    "url": "https://your-domain.example/source.mp4"
                  },
                  "role": "reference_video"
                }
              ]
            }
            """;
        HttpRequest request = HttpRequest.newBuilder(URI.create(base + path))
            .timeout(Duration.ofSeconds(120))
            .header("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
            .header("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20)).build();
        // 网络异常会抛出异常;重试创建请求时保留相同幂等键和参数。
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        System.out.println(response.body());
        if (response.statusCode() >= 400) {
            throw new IllegalStateException("HTTP " + response.statusCode());
        }
    }
}

Go 1.20+,仅使用标准库。保存为 main.go,运行 go run main.go。

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requireEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("请设置环境变量 " + name) }
    return value
}

func main() {
    base := os.Getenv("MASS_BASE_URL")
    if base == "" { base = "https://api.vizen.cc" }
    base = strings.TrimRight(base, "/")
    path := "/v1/video-generations"
    body := `{
  "model": "doubao-seedance-2-5-260628",
  "omni_reference_task_type": "extend",
  "duration": 8,
  "output_format": "mov",
  "content": [
    {
      "type": "text",
      "text": "向后延长视频,人物继续向前走,保持原有光线"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://your-domain.example/source.mp4"
      },
      "role": "reference_video"
    }
  ]
}`
    req, err := http.NewRequest("POST", base + path, strings.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
    req.Header.Set("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 120 * time.Second}
    resp, err := client.Do(req)
    // 网络异常不代表创建失败;重试时保留原幂等键和参数。
    if err != nil { panic(err) }
    defer resp.Body.Close()
    data, err := io.ReadAll(resp.Body)
    if err != nil { panic(err) }
    fmt.Println(string(data))
    if resp.StatusCode >= 400 { panic(fmt.Sprintf("HTTP %d", resp.StatusCode)) }
}

文本生成与可选工具

Bash / macOS / Linux;Windows 可使用 Git Bash。

# 先按“鉴权与通用约定”设置环境变量
: "${MASS_API_KEY:?请先设置 MASS_API_KEY}"
: "${MASS_IDEMPOTENCY_KEY:?请设置本次业务请求的幂等键;重试时保持不变}"
MASS_BASE_URL="${MASS_BASE_URL:-https://api.vizen.cc}"

curl --silent --show-error --fail-with-body --max-time 120 \
  -X POST "${MASS_BASE_URL%/}/v1/video-generations" \
  -H "Authorization: Bearer $MASS_API_KEY" \
  -H "Idempotency-Key: $MASS_IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "model": "doubao-seedance-2-5-260628",
  "content": [
    {
      "type": "text",
      "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
    }
  ],
  "resolution": "720p",
  "duration": 5,
  "ratio": "16:9",
  "tools": [
    {
      "type": "web_search"
    }
  ],
  "priority": 0,
  "callback_url": "https://your-domain.example/mass/task-result"
}
JSON

Python 3.10+,仅使用标准库。保存为 example.py,运行 python example.py。

import json
import os
import urllib.error
import urllib.parse
import urllib.request

base_url = os.environ.get("MASS_BASE_URL", "https://api.vizen.cc").rstrip("/")
api_key = os.environ["MASS_API_KEY"]
path = "/v1/video-generations"
headers = {"Authorization": "Bearer " + api_key}
headers["Idempotency-Key"] = os.environ["MASS_IDEMPOTENCY_KEY"]
payload = json.loads(r'''{
  "model": "doubao-seedance-2-5-260628",
  "content": [
    {
      "type": "text",
      "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
    }
  ],
  "resolution": "720p",
  "duration": 5,
  "ratio": "16:9",
  "tools": [
    {
      "type": "web_search"
    }
  ],
  "priority": 0,
  "callback_url": "https://your-domain.example/mass/task-result"
}''')
headers["Content-Type"] = "application/json"
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
request = urllib.request.Request(
    base_url + path, data=body, headers=headers, method="POST"
)
try:
    with urllib.request.urlopen(request, timeout=120) as response:
        result = json.load(response)
        print(json.dumps(result, ensure_ascii=False, indent=2))
except urllib.error.HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))
    raise SystemExit(1)
except urllib.error.URLError as error:
    # 创建请求出现网络异常时,保留原幂等键;不要生成新键后盲目重试。
    print("请求未能确认:", error.reason)
    raise SystemExit(1)

JDK 17+,仅使用标准库。保存为 UTF-8 的 Example.java;执行 javac -encoding UTF-8 Example.java,再执行 java Example。

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class Example {
    static String requireEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) {
            throw new IllegalArgumentException("请设置环境变量 " + name);
        }
        return value;
    }

    public static void main(String[] args) throws Exception {
        String base = System.getenv().getOrDefault("MASS_BASE_URL", "https://api.vizen.cc");
        base = base.replaceAll("/+$", "");
        String path = "/v1/video-generations";
        String body = """
            {
              "model": "doubao-seedance-2-5-260628",
              "content": [
                {
                  "type": "text",
                  "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
                }
              ],
              "resolution": "720p",
              "duration": 5,
              "ratio": "16:9",
              "tools": [
                {
                  "type": "web_search"
                }
              ],
              "priority": 0,
              "callback_url": "https://your-domain.example/mass/task-result"
            }
            """;
        HttpRequest request = HttpRequest.newBuilder(URI.create(base + path))
            .timeout(Duration.ofSeconds(120))
            .header("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
            .header("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20)).build();
        // 网络异常会抛出异常;重试创建请求时保留相同幂等键和参数。
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        System.out.println(response.body());
        if (response.statusCode() >= 400) {
            throw new IllegalStateException("HTTP " + response.statusCode());
        }
    }
}

Go 1.20+,仅使用标准库。保存为 main.go,运行 go run main.go。

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requireEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("请设置环境变量 " + name) }
    return value
}

func main() {
    base := os.Getenv("MASS_BASE_URL")
    if base == "" { base = "https://api.vizen.cc" }
    base = strings.TrimRight(base, "/")
    path := "/v1/video-generations"
    body := `{
  "model": "doubao-seedance-2-5-260628",
  "content": [
    {
      "type": "text",
      "text": "清晨的海边,镜头缓慢推进,海浪轻拍沙滩"
    }
  ],
  "resolution": "720p",
  "duration": 5,
  "ratio": "16:9",
  "tools": [
    {
      "type": "web_search"
    }
  ],
  "priority": 0,
  "callback_url": "https://your-domain.example/mass/task-result"
}`
    req, err := http.NewRequest("POST", base + path, strings.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer " + requireEnv("MASS_API_KEY"))
    req.Header.Set("Idempotency-Key", requireEnv("MASS_IDEMPOTENCY_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 120 * time.Second}
    resp, err := client.Do(req)
    // 网络异常不代表创建失败;重试时保留原幂等键和参数。
    if err != nil { panic(err) }
    defer resp.Body.Close()
    data, err := io.ReadAll(resp.Body)
    if err != nil { panic(err) }
    fmt.Println(string(data))
    if resp.StatusCode >= 400 { panic(fmt.Sprintf("HTTP %d", resp.StatusCode)) }
}

成功响应

HTTP 202 表示受理,返回任务 id。保存 id 后查询任务;不代表视频已生成完成。

{
  "id": "job_example"
}
idstring

平台任务 ID,用于查询和取消

查询使用官方风格的 content.video_url、Unix 秒级时间戳及 usage,地址指向最终视频。return_last_frame 参数可提交,但不返回 content.last_frame_url;尾帧输入仍可正常使用。输出不会包含实际渠道 ID、素材审核 ID 或中间视频地址。完整结构见任务查询。

搜索文档

↑ ↓ 选择 · Enter 跳转

输入关键词,搜索正文、参数和代码示例。