跳到主要內容

API 文件 · 火山 V3 相容介面

方舟相容介面

已按火山方舟寫好的程式只換位址和金鑰接入:影片任務、素材庫、真人認證。

已經按火山方舟(Volcano Ark)寫好的程式或平台,可以只換位址和金鑰接入本平台:請求、回應的結構與方舟相同,計費與 /v1 介面完全一樣。新接入建議直接用 /v1。

位址與鑑權

用途本平台鑑權
影片任務(推理面)https://api.aitoken.tools/api/v3Authorization: Bearer <API Key>
素材庫、真人認證(管控面)https://api.aitoken.tools/?Action=…&Version=2024-01-01(SDK 裡主機名填 api.aitoken.tools,Region ap-southeast-1,Service ark)AccessKey 按火山 V4 簽章:AccessKeyId 在主控台「API Key」頁查看(AKAT…),SecretAccessKey 就是這把 API Key 本身;也可以直接用 Bearer API Key

從官方遷移只改三處:Base URL / 主機名、金鑰、已有素材重新匯入一次(你自己火山帳號下素材庫裡的素材 ID 在本平台不能用)。

影片任務

方舟介面說明
POST /api/v3/contents/generations/tasks建立,回傳 { "id": "task_…" }
GET /api/v3/contents/generations/tasks/{id}查詢,回傳方舟的任務結構,另附本平台欄位 aitoken(扣費金額、實際模型)
GET /api/v3/contents/generations/tasks列表:page_num、page_size(≤ 500,預設 10)、filter.status、filter.task_ids、filter.model
DELETE /api/v3/contents/generations/tasks/{id}暫不支援取消或刪除
  • model:本平台的模型名或官方模型 ID(如 dreamina-seedance-2-0-260128)都可以;推論接入點 ep-… 不能用。
  • content:圖片、影片、音訊的 url 可以是 http(s) 連結(平台當場匯入,同一連結重複使用,放進「方舟接口自動導入」分組)、data:…;base64,…(圖片 ≤ 30 MB、音訊 ≤ 15 MB、影片 ≤ 10 MB;整個請求內容 ≤ 64 MiB)或 asset://asset_…(本平台素材)。圖片沒寫 role 時:一張按首幀,兩張按首幀 + 尾幀,更多張請寫明 role。
  • 預設值與方舟一致:resolution 720p、duration 5;有圖片輸入時 ratio 為 adaptive,否則 16:9。watermark、seed、generate_audio 等模型參數原樣傳;模型不支援的參數回傳 400。
  • 方舟沒有冪等鍵:請求標頭帶 Idempotency-Key 就按它去重;網路逾時後請先查詢,不要直接重送。callback_url 回呼的內容是方舟的任務結構。

素材庫

支援的 Action(參數與結果欄位同方舟素材庫;ID 是本平台格式):

CreateAssetGroup GetAssetGroup ListAssetGroups UpdateAssetGroup DeleteAssetGroup CreateAsset GetAsset ListAssets UpdateAsset DeleteAsset

素材組的 GroupType 與方舟一致:一般素材組是 AIGC,真人分組是 LivenessFace(先前回傳的是 RealPerson,依這個值判斷的程式請改掉)。CreateAssetGroup 的 GroupType 只接受 AIGC(可不填),其他值回傳 400;真人分組要透過 CreateVisualValidateSession 建立。ListAssetGroups 支援 Filter.GroupType(AIGC / LivenessFace,其他值回傳 400)和 Filter.GroupIds。

素材使用流程

  1. CreateAsset 依 URL 建立素材。回傳的 Result.Id(asset_…)就是素材 ID,後續查詢和引用都用它;Name 只是名稱,不能當 ID 用。素材是非同步匯入的,建立成功時就會回傳 Id。
    POST /?Action=CreateAsset&Version=2024-01-01
    {
      "GroupId": "grp_xxx",
      "URL": "https://example.com/role-a.png",
      "AssetType": "Image",
      "Name": "role-a"
    }
    {
      "ResponseMetadata": { "RequestId": "req_xxx", "Action": "CreateAsset", … },
      "Result": { "Id": "asset_xxx" }
    }
  2. 用 GetAsset 查狀態:Status 為 Active 才能用;Processing 繼續等(一般幾秒),Failed 看 FailReason。
    POST /?Action=GetAsset&Version=2024-01-01
    { "Id": "asset_xxx" }
    {
      "ResponseMetadata": { … },
      "Result": {
        "Id": "asset_xxx",
        "Name": "role-a",
        "Status": "Active",
        "AssetType": "Image",
        "GroupId": "grp_xxx",
        "URL": "https://…"
      }
    }
  3. 產生影片時在 content[] 裡用 asset://<Result.Id> 引用(圖片的 role 依用途寫 first_frame / last_frame / reference_image):
    {
      "type": "image_url",
      "image_url": { "url": "asset://asset_xxx" },
      "role": "reference_image"
    }

不想管素材庫的話,也可以在 content[] 裡直接給圖片的 http(s) 連結,平台會當場匯入(見上一節)。

真人認證

  1. CreateVisualValidateSession:回傳 H5Link、BytedToken(本平台的認證 ID,auth_…)和 GroupId(為這次認證新建的真人分組)。可選參數 Model 指定模型,不填時按你已開通的模型自動選擇。可選參數 CallbackURL(http 或 https 的完整位址,不帶使用者名稱密碼,最長 2048 字元)是認證完成後要回到的頁面。
  2. 把 H5Link 交給本人刷臉,30 分鐘內有效。完成後瀏覽器會跳到你傳的 CallbackURL,並帶上兩個查詢參數:bytedToken(本平台的認證 ID auth_…,與 CreateVisualValidateSession 回傳的 BytedToken 相同)和 resultCode(上游的結果碼,10000 表示通過,可能沒有)。收到跳轉後請用這個 bytedToken 呼叫 GetVisualValidateResult 確認結果,不要只憑 resultCode 判斷;跳轉到達時結果可能還沒出來,回傳 Processing 就每隔 5 秒以上再查,直到 Success 或 Failed(個別線路要幾分鐘)。個別線路刷臉後不會回到 CallbackURL,所以即使傳了 CallbackURL,也請保留輪詢作為備援。沒傳 CallbackURL 時頁面停在本站的提示頁,請輪詢 GetVisualValidateResult。
  3. GetVisualValidateResult:Status 為 Success 時回傳 GroupId;Processing 表示還沒完成。
  4. 用 CreateAsset 往這個 GroupId 裡加本人的照片:自動按真人素材處理,可用後即可在任務裡使用。認證通過前往分組加素材會被拒絕。

與方舟官方的差異

  • 任務、素材、分組、認證的 ID 都是本平台格式(task_…、asset_…、grp_…、auth_…),程式裡不要按火山 ID 的前綴判斷。
  • 錯誤碼是本平台的(見「錯誤碼」一節),放在方舟的錯誤結構裡;參數錯誤回傳 400。
  • 只能用本平台已上架、並為你開通的模型;對話、圖片等其他方舟介面不在此列,對話請用 /v1/chat/completions。
  • 經濟版模型不在方舟相容介面提供(按模型不存在處理),請用 /v1/videos/generations。
# 建立影片任務:請求體與方舟相同,只換位址和 Key
curl https://api.aitoken.tools/api/v3/contents/generations/tasks \
  -H "Authorization: Bearer $AITOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dreamina-seedance-2-0-260128",
    "content": [
      { "type": "text", "text": "鏡頭緩緩推進,晨霧中的山間小鎮" },
      { "type": "image_url", "image_url": { "url": "https://example.com/first.png" }, "role": "first_frame" }
    ],
    "ratio": "adaptive",
    "duration": 5
  }'

# 查詢任務(方舟的任務結構)
curl https://api.aitoken.tools/api/v3/contents/generations/tasks/task_xxx \
  -H "Authorization: Bearer $AITOKEN_API_KEY"

# 素材庫:依連結建立素材。也可以用 AccessKey 按火山 V4 簽章呼叫
curl "https://api.aitoken.tools/?Action=CreateAsset&Version=2024-01-01" \
  -H "Authorization: Bearer $AITOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"GroupId":"grp_xxx","URL":"https://example.com/role-a.png","AssetType":"Image","Name":"role-a"}'
# 回傳:素材 ID 在 Result.Id(Name 只是名稱,不能當 ID 用)
# {"ResponseMetadata":{"RequestId":"req_xxx","Action":"CreateAsset",…},"Result":{"Id":"asset_xxx"}}

# 查狀態:Status 變為 Active 才能用(Processing 繼續等,Failed 看 FailReason)
curl "https://api.aitoken.tools/?Action=GetAsset&Version=2024-01-01" \
  -H "Authorization: Bearer $AITOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"Id":"asset_xxx"}'
# {"ResponseMetadata":{…},"Result":{"Id":"asset_xxx","Name":"role-a","Status":"Active","AssetType":"Image","GroupId":"grp_xxx",…}}

# 產生影片時用 asset://<Result.Id> 引用這個素材
curl https://api.aitoken.tools/api/v3/contents/generations/tasks \
  -H "Authorization: Bearer $AITOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dreamina-seedance-2-0-260128",
    "content": [
      { "type": "text", "text": "鏡頭緩緩推進,晨霧中的山間小鎮" },
      { "type": "image_url", "image_url": { "url": "asset://asset_xxx" }, "role": "reference_image" }
    ]
  }'