クイックスタート
Seedance API(v3)
https://api.tokenlio.ai とプラットフォーム Bearer Key、現在の一覧にある正確な model ID を使用します。詳細なフィールドは公式資料も参照でき、呼び出しには本ページのアドレス・認証・例を使用してください。
まずテキストから動画を1件作成し、idを保存して同じタスクを照会します。素材管理と人物認証は必要に応じて使用する手順で、通常の生成の前提ではありません。
目的別の手順
| 目的 | 読む順序 |
|---|---|
| 最初の動画を生成 | 動画タスクの作成 → タスクの照会と管理 |
| 画像・動画・音声素材を再利用 | 素材グループと素材管理 → 動画タスクの作成 |
| 人物素材を認証 | 人物素材認証 → 素材グループと素材管理 → 動画タスクの作成 |
| 生成通知を受信 | 生成結果コールバック → タスクの照会と管理 |
| Agentによる呼び出し編成 | Agent 接続ガイド → 呼び出し規約 |
クイックスタート
TOKENLIO_API_KEY と今回の生成意図に固定した TOKENLIO_IDEMPOTENCY_KEY を設定してください。新しい意図のみ新しいキーを使い、不明な結果の復元では元のキー/本文を維持します。例は実際の生成を行うため、先にmockでロジックを検証してください。
bash
# 1. 動画タスクを作成
curl -sS --fail-with-body -X POST "https://api.tokenlio.ai/api/v3/contents/generations/tasks" \
-H "Authorization: Bearer $TOKENLIO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: ${TOKENLIO_IDEMPOTENCY_KEY:?Set a stable intent key}" \
--data '{
"model": "seedance-2.0",
"content": [
{
"type": "text",
"text": "雨上がりの水たまりを紙の舟が流れ、カメラがゆっくり近づく"
}
],
"resolution": "720p",
"ratio": "16:9",
"duration": 5,
"generate_audio": false
}'
# 2. タスクを照会。TASK_ID は作成レスポンスの id
curl -sS --fail-with-body -X GET "https://api.tokenlio.ai/api/v3/contents/generations/tasks/TASK_ID" \
-H "Authorization: Bearer $TOKENLIO_API_KEY"python
import os
import time
import requests
BASE_URL = "https://api.tokenlio.ai"
headers = {
"Authorization": f"Bearer {os.environ['TOKENLIO_API_KEY']}",
"Content-Type": "application/json",
"Idempotency-Key": os.environ["TOKENLIO_IDEMPOTENCY_KEY"],
}
# 1. 動画タスクを作成
payload = {
"model": "seedance-2.0",
"content": [
{
"type": "text",
"text": "雨上がりの水たまりを紙の舟が流れ、カメラがゆっくり近づく"
}
],
"resolution": "720p",
"ratio": "16:9",
"duration": 5,
"generate_audio": False
}
response = requests.post(
f"{BASE_URL}/api/v3/contents/generations/tasks",
headers=headers,
json=payload,
timeout=30,
)
response.raise_for_status()
task_id = response.json()["id"]
print("Task ID:", task_id)
# タスクの照会
while True:
time.sleep(5)
response = requests.get(
f"{BASE_URL}/api/v3/contents/generations/tasks/{task_id}",
headers=headers,
timeout=30,
)
response.raise_for_status()
task = response.json()
if task["status"] == "succeeded":
print("動画 URL:", task["content"]["video_url"])
break
if task["status"] in {"failed", "cancelled", "expired"}:
print("タスク状態:", task["status"], task.get("error"))
breakjavascript
const baseUrl = "https://api.tokenlio.ai";
if (!process.env.TOKENLIO_IDEMPOTENCY_KEY) throw new Error("Set a stable intent key");
const headers = {
Authorization: `Bearer ${process.env.TOKENLIO_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": process.env.TOKENLIO_IDEMPOTENCY_KEY,
};
// 1. 動画タスクを作成
const response = await fetch(`${baseUrl}/api/v3/contents/generations/tasks`, {
method: "POST",
headers,
body: JSON.stringify({
"model": "seedance-2.0",
"content": [
{
"type": "text",
"text": "雨上がりの水たまりを紙の舟が流れ、カメラがゆっくり近づく"
}
],
"resolution": "720p",
"ratio": "16:9",
"duration": 5,
"generate_audio": false
}),
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
const { id } = await response.json();
console.log("Task ID:", id);
// タスクの照会
while (true) {
await new Promise(resolve => setTimeout(resolve, 5000));
const query = await fetch(`${baseUrl}/api/v3/contents/generations/tasks/${id}`, { headers });
if (!query.ok) throw new Error(`${query.status}: ${await query.text()}`);
const task = await query.json();
if (task.status === "succeeded") {
console.log("動画 URL:", task.content.video_url);
break;
}
if (["failed", "cancelled", "expired"].includes(task.status)) {
console.log("タスク状態:", task.status, task.error);
break;
}
}レスポンス例
作成レスポンス
json
{
"id": "dfc68868-d388-4d83-a173-d44e47a8bec7"
}生成成功時の照会レスポンス
json
{
"id": "dfc68868-d388-4d83-a173-d44e47a8bec7",
"model": "seedance-2.0",
"status": "succeeded",
"content": {
"video_url": "https://example.com/result.mp4"
},
"resolution": "720p",
"duration": 5,
"usage": {
"completion_tokens": 108900,
"total_tokens": 108900
}
}作成は HTTP 200 とタスク id を返します。照会は状態、結果 URL、使用量を返します。content.video_url は一時的な URL で、再照会では更新されません。
