Skip to content

Seedance API Examples

由于Seedance模型是一个多模态模型,OpenAI SDK 目前不支持直接访问该模型。您需要使用request方式访问Seedance模型。

基础配置

在开始使用API之前,请确保您已经获取了API Key。如果还没有,请参考创建API Key

基础信息

  • API Base URL: https://api.agentsflare.com/byteplus/v3/contents/generations/tasks
  • 认证方式: Bearer Token
  • 内容类型: application/json

请求示例

创建视频

bash
curl --location --request POST 'https://api.agentsflare.com/byteplus/v3/contents/generations/tasks' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {API-KEY}' \
--data-raw '{
    "model": "seedance-1-0-pro-250528",
    "content": [
        {
            "type": "text",
            "text": "图片中的女士,开着跑车冲出展台,撞碎展厅玻璃。"
        },
        {
            "type": "image_url",
            "image_url": {
                "url": "https://*******.jpeg|png...."
            }
        }
    ],
    "ratio": "adaptive",
    "duration": 6,
    "watermark": false
}'
python
import requests
import json

url = "https://api.agentsflare.com/byteplus/v3/contents/generations/tasks"

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer {API-KEY}"
}

payload = {
    "model": "seedance-1-0-pro-250528",
    "content": [
        {
            "type": "text",
            "text": "图片中的女士,开着跑车冲出展台,撞碎展厅玻璃。"
        },
        {
            "type": "image_url",
            "image_url": {
                "url": "https://*******.jpeg|png...."
            }
        }
    ],
    "ratio": "adaptive",
    "duration": 6,
    "watermark": False
}

response = requests.post(url, headers=headers, json=payload)

print(response.status_code)
print(response.json())
javascript
const fetch = require('node-fetch');

const url = 'https://api.agentsflare.com/byteplus/v3/contents/generations/tasks';

const payload = {
    model: 'seedance-1-0-pro-250528',
    content: [
        {
            type: 'text',
            text: '图片中的女士,开着跑车冲出展台,撞碎展厅玻璃。'
        },
        {
            type: 'image_url',
            image_url: {
                url: 'https://*******.jpeg|png....'
            }
        }
    ],
    ratio: 'adaptive',
    duration: 6,
    watermark: false
};

const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {API-KEY}'
    },
    body: JSON.stringify(payload)
};

fetch(url, options)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
go

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	url := "https://api.agentsflare.com/byteplus/v3/contents/generations/tasks"

	payload := map[string]interface{}{
		"model": "seedance-1-0-pro-250528",
		"content": []map[string]interface{}{
			{
				"type": "text",
				"text": "图片中的女士,开着跑车冲出展台,撞碎展厅玻璃。",
			},
			{
				"type": "image_url",
				"image_url": map[string]string{
					"url": "https://*******.jpeg|png....",
				},
			},
		},
		"ratio":     "adaptive",
		"duration":  6,
		"watermark": false,
	}

	jsonData, err := json.Marshal(payload)
	if err != nil {
		fmt.Println("Error marshaling JSON:", err)
		return
	}

	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer {API-KEY}")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}

	fmt.Println("Status:", resp.StatusCode)
	fmt.Println("Response:", string(body))
}

响应示例

创建成功后返回任务ID,您可以使用该ID查询任务状态和下载视频。

json
{
  "id": "cgt-2026******-****"
}

文件检索

bash
curl --location --request GET 'https://api.agentsflare.com/byteplus/v3/contents/generations/tasks/cgt-2026******-****' \
--header 'Authorization: Bearer {API-KEY}'
python
import requests

url = "https://api.agentsflare.com/byteplus/v3/contents/generations/tasks/cgt-2026******-****"

headers = {
    "Authorization": "Bearer {API-KEY}"
}

response = requests.get(url, headers=headers)

print(response.status_code)
print(response.json())
javascript
const fetch = require('node-fetch');

const url = 'https://api.agentsflare.com/byteplus/v3/contents/generations/tasks/cgt-2026******-****';

const options = {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer {API-KEY}'
    }
};

fetch(url, options)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
go

package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	url := "https://api.agentsflare.com/byteplus/v3/contents/generations/tasks/cgt-2026******-****"

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	req.Header.Set("Authorization", "Bearer {API-KEY}")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}

	fmt.Println("Status:", resp.StatusCode)
	fmt.Println("Response:", string(body))
}

响应实例

视频状态响应中包含视频的下载地址,您可以直接访问该地址下载视频。

json
{
    "id": "cgt-2026******-****",
    "model": "seedance-1-0-pro-250528",
    "status": "succeeded",
    "content": {
        "video_url": "https://ark-content-generation-ap-southeast-1.tos-ap-southeast-1.volces.com/seedance-1-0-pro/021768294532558000000000ffffc0a8bc10474251.mp4?X************"
    },
    "usage": {
        "completion_tokens": 295800,
        "total_tokens": 295800
    },
    "created_at": 1768294532,
    "updated_at": 1768294581,
    "seed": 44457,
    "resolution": "1080p",
    "ratio": "16:9",
    "duration": 6,
    "framespersecond": 24,
    "service_tier": "default",
    "execution_expires_after": 172800,
    "draft": false
}

请求参数

更多请求方式和参数详见Seedance 请求参数

本文档遵循 CC BY-SA 4.0 协议。