非同步任務
取得任務狀態
使用建立端點回傳的 `poll_url` 來取得任何非同步任務的狀態與結果
概覽
使用此端點對影片、影像、音樂與 3D 生成等任務類型進行統一的非同步輪詢。
如果建立回應包含 poll_url,請呼叫該精確路徑。某些影像模型可能會在影像專用的狀態路徑或 /v1/tasks/{id} 下回傳基於任務的回應。
路徑參數
由建立請求返回的任務 ID。
回應
結果、錯誤、時間戳記與模型欄位僅在任務提供時回傳。
標準的非同步任務識別碼。
非同步任務識別符別名。
當建立回應提供時,首選的輪詢 URL。
任務狀態,例如 pending、processing、completed 或 failed。已取消的任務會表示為 failed 並帶有 cancelled: true。
排隊中的非同步任務在執行前被取消時為 true。
取消標記。取消成功時為 cancelled。
對於已完成的圖片任務,生成的圖片結果會在這裡返回。圖片任務會在 data[].url 中返回 URL。
可選進度值。僅在任務提供真實進度時返回;請使用 status 判斷任務是否完成。
任務完成並產生影片時的結果資產 URL。
單一影片載荷,包含 url、duration、width 與 height(若可用)。
存在多於一個輸出時的多個影片載荷。
任務失敗時的錯誤訊息。
可用時的建立時間戳。
可用時的最後更新時間戳。
可用時任務使用的模型。
錯誤行為
已過期或不可用的公開任務可能回傳 404 async_task_not_found。無法確認目前 API 金鑰對任務的歸屬權限時,回傳 403 task_not_owned。
{
"error": {
"message": "Task not found or no longer available.",
"type": "invalid_request_error",
"code": "async_task_not_found"
}
}範例
請求
curl "https://api.tokenlab.sh/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
-H "Authorization: Bearer sk-your-api-key"import requests
poll_url = "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
response = requests.get(
f"https://api.tokenlab.sh{poll_url}",
headers={"Authorization": "Bearer sk-your-api-key"},
)
print(response.json())const pollUrl = '/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const response = await fetch(`https://api.tokenlab.sh${pollUrl}`, {
headers: { Authorization: 'Bearer sk-your-api-key' },
});
console.log(await response.json());{ "id": "string", "status": "pending", "progress": 0, "created": 0, "updated": 0, "model": "string", "video": { "url": "string", "duration": 0, "width": 0, "height": 0 }, "error": "string", "error_details": { "projection_version": 0, "status": 400, "message": "string", "type": "string", "code": "string", "param": "string", "retryable": true, "upstream": { "source": "string", "code": "string", "message": "string", "param": "string" } }, "task_id": "string", "poll_url": "string", "cancelled": true, "cancellation_status": "cancelled", "billing_transaction_id": "string", "video_url": "string", "videos": [ {} ], "data": [ {} ], "audio_url": "string", "title": "string", "lyrics": "string", "model_url": "string", "glb_url": "string", "fbx_url": "string"}授權
BearerAuth API Key 驗證。請在 Dashboard > API > API Keys 建立或管理 API 金鑰。
位置: header
路徑參數
由 id / task_id 回傳,或嵌入於 poll_url 中的非同步任務 ID
回應
application/json
application/json
application/json
application/json