跳转到主要内容

推荐 endpoint

最小请求

{
  "model": "sora-2",
  "prompt": "一段 8 秒的 Api.Go 产品演示动画",
  "seconds": 8,
  "size": "1280x720"
}

cURL 示例

VIDEO_ID=$(curl -s https://mass.apigo.ai/v1/videos \
  -H "Authorization: Bearer $TIDEMIND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sora-2",
    "prompt": "一段 8 秒的 Api.Go 产品演示动画",
    "seconds": 8,
    "size": "1280x720"
  }' | jq -r '.id')

while true; do
  STATUS=$(curl -s \
    -H "Authorization: Bearer $TIDEMIND_API_KEY" \
    "https://mass.apigo.ai/v1/videos/$VIDEO_ID")

  STATE=$(echo "$STATUS" | jq -r '.status')
  if [ "$STATE" = "completed" ]; then
    curl -L \
      -H "Authorization: Bearer $TIDEMIND_API_KEY" \
      "https://mass.apigo.ai/v1/videos/$VIDEO_ID/content" \
      -o tidemind-demo.mp4
    break
  fi

  if [ "$STATE" = "failed" ]; then
    echo "$STATUS"
    break
  fi

  sleep 10
done

Python 示例

import time
import requests

headers = {"Authorization": "Bearer <TIDEMIND_API_KEY>"}

create_response = requests.post(
    "https://mass.apigo.ai/v1/videos",
    headers={**headers, "Content-Type": "application/json"},
    json={
        "model": "sora-2",
        "prompt": "一段 8 秒的 Api.Go 产品演示动画",
        "seconds": 8,
        "size": "1280x720",
    },
    timeout=60,
)
create_response.raise_for_status()
video_id = create_response.json()["id"]

while True:
    status_response = requests.get(
        f"https://mass.apigo.ai/v1/videos/{video_id}",
        headers=headers,
        timeout=60,
    )
    status_response.raise_for_status()
    status = status_response.json()["status"]

    if status == "completed":
        content_response = requests.get(
            f"https://mass.apigo.ai/v1/videos/{video_id}/content",
            headers=headers,
            timeout=120,
        )
        content_response.raise_for_status()
        with open("tidemind-demo.mp4", "wb") as f:
            f.write(content_response.content)
        print("saved tidemind-demo.mp4")
        break

    if status == "failed":
        raise RuntimeError(status_response.text)

    time.sleep(10)

Node.js 示例

import { writeFileSync } from "node:fs";

const headers = {
  Authorization: `Bearer ${process.env.TIDEMIND_API_KEY}`,
  "Content-Type": "application/json"
};

const createResponse = await fetch("https://mass.apigo.ai/v1/videos", {
  method: "POST",
  headers,
  body: JSON.stringify({
    model: "sora-2",
    prompt: "一段 8 秒的 Api.Go 产品演示动画",
    seconds: 8,
    size: "1280x720"
  })
});

const { id: videoId } = await createResponse.json();

while (true) {
  const statusResponse = await fetch(
    `https://mass.apigo.ai/v1/videos/${videoId}`,
    { headers: { Authorization: headers.Authorization } }
  );
  const statusData = await statusResponse.json();

  if (statusData.status === "completed") {
    const contentResponse = await fetch(
      `https://mass.apigo.ai/v1/videos/${videoId}/content`,
      { headers: { Authorization: headers.Authorization } }
    );
    const buffer = Buffer.from(await contentResponse.arrayBuffer());
    writeFileSync("tidemind-demo.mp4", buffer);
    console.log("saved tidemind-demo.mp4");
    break;
  }

  if (statusData.status === "failed") {
    throw new Error(JSON.stringify(statusData));
  }

  await new Promise((resolve) => setTimeout(resolve, 10000));
}

最佳实践

  • 创建、查状态、取内容三步拆开,不要假设提交成功就有最终视频
  • 轮询间隔控制在合理区间,并做退避
  • 下载大文件或临时 URL 时,优先由服务端代理