API 參考

Veo 3.1 AI 影片生成完整 API 文件

概述

Veo 3.1 API 允許您透過程式化方式從文字描述或圖片生成 AI 影片。我們的 RESTful API 設計簡潔、功能強大,易於整合到您的應用程式中。

基礎 URL

https://veo3o1.com/api

認證

所有 API 請求都需要使用 API 金鑰進行認證。在 Authorization 請求標頭中包含您的 API 金鑰:

Authorization: Bearer YOUR_API_KEY

您可以在帳戶儀表板中產生 API 金鑰。


生成影片

從文字或圖片建立新的 AI 影片。

端點

POST /generate-video

請求主體

{
  "generationType": "text_to_video" | "image_to_video",
  "prompt": "Your video description",
  "aspectRatio": "auto" | "16:9" | "9:16",
  "imageUrl": "https://...", // Required if generationType is "image_to_video"
  "imageKey": "r2-key" // Optional, for uploaded images
}

參數

參數類型必填描述
generationTypestring生成類型:text_to_videoimage_to_video
promptstring您想要生成的影片描述
aspectRatiostring影片寬高比。預設:auto
imageUrlstring條件必填generationTypeimage_to_video 時必填
imageKeystring已上傳圖片的儲存金鑰

回應

{
  "code": 0,
  "msg": "Success",
  "data": {
    "uuid": "video-uuid-123",
    "status": "pending",
    "generationType": "text_to_video",
    "prompt": "Your video description",
    "aspectRatio": "16:9",
    "createdAt": "2025-10-16T10:00:00Z"
  }
}

範例

curl -X POST https://veo3o1.com/api/generate-video \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "generationType": "text_to_video",
    "prompt": "A beautiful sunset over the ocean with waves gently lapping the shore",
    "aspectRatio": "16:9"
  }'

取得影片狀態

檢查影片生成請求的狀態。

端點

GET /video-status/{uuid}

參數

參數類型必填描述
uuidstring生成請求回傳的影片 UUID

回應

{
  "code": 0,
  "msg": "Success",
  "data": {
    "uuid": "video-uuid-123",
    "status": "completed" | "pending" | "processing" | "failed",
    "videoUrl": "https://...", // Available when status is "completed"
    "progress": 85, // Processing progress (0-100)
    "estimatedTime": 120 // Estimated seconds remaining
  }
}

狀態值

  • pending:影片已排隊等待處理
  • processing:影片正在生成中
  • completed:影片已就緒,可供下載
  • failed:生成失敗(請查看錯誤訊息)

上傳圖片

上傳圖片用於圖片轉影片生成。

端點

POST /upload-video-image

請求

使用 multipart/form-data 上傳圖片檔案。

curl -X POST https://veo3o1.com/api/upload-video-image \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@/path/to/image.jpg"

回應

{
  "code": 0,
  "msg": "Upload successful",
  "data": {
    "imageUrl": "https://...",
    "imageKey": "r2-key-123"
  }
}

支援的格式

  • JPEG/JPG
  • PNG
  • WebP
  • 最大檔案大小:50MB

錯誤代碼

代碼描述
0成功
1000參數無效
1001積分不足
1002認證失敗
1003超出速率限制
5000伺服器錯誤

錯誤回應範例

{
  "code": 1001,
  "msg": "Insufficient credits",
  "data": {
    "required": 2,
    "current": 0
  }
}

最佳實踐

  1. 合理輪詢:每 5-10 秒檢查一次影片狀態,不要持續輪詢
  2. 處理錯誤:實作帶指數退避的重試邏輯
  3. 快取結果:儲存已生成的影片以避免重複生成
  4. 使用 Webhooks:比輪詢更高效的完成通知方式
  5. 驗證輸入:在呼叫 API 前檢查提示詞長度和圖片格式

支援

需要 API 幫助?