Text to Motion API

根據自然語言描述產生角色動作片段。描述一個動作——「一個角色在揮手」、「一個殭屍蹣跚前行」——即可取得一個原始動作片段,你可以在自己的管線或 DCC 工具中,將其重定向套用到已完成骨骼綁定的角色上。

輸出結果是一個獨立的動作片段:它不需要角色模型,也不會附加到任何角色模型上。若要先為角色進行骨骼綁定,請參閱 Rigging API。若要將產生的片段套用到已完成骨骼綁定的角色上,請將任務 id 作為 motion_task_id 傳遞給 Animation API——請在 3 天的資產保留期限內完成套用。


POST/openapi/v1/text-to-motion

創建文本生成動作任務

此 endpoint 用於創建一個新任務,根據文本 prompt 生成動作片段。

modeprime 的任務消耗 10 積分,使用我們品質最高的動作模型進行生成。modeswift 的任務消耗 3 積分,使用我們經濟型動作模型更快地生成。

參數

  • Name
    prompt
    Type
    string
    必選
    Description

    對要生成的動作的自然語言描述。最多 400 個字元。

  • Name
    mode
    Type
    string
    預設值 prime
    Description

    動作生成 mode。可選值:primeswiftprime 生成品質最高,輸出 FBX;swift 更快更經濟,輸出 BVH。

  • Name
    duration
    Type
    number
    必選
    Description

    動作片段的目標時長(秒)。範圍在 210 之間,步長為 0.5(例如 22.53、……、10)。

回傳

響應中的 result 屬性包含新創建的文本生成動作任務的任務 id

失敗模式

  • Name
    400 - Bad Request
    Description

    請求不可接受。常見原因:

    • prompt 缺失或為空prompt 缺失、為空,或超過 400 個字元。
    • mode 無效mode 不是 primeswift
    • duration 無效duration 缺失、不在 210 範圍內,或不是 0.5 秒的整數倍步長。
  • Name
    401 - Unauthorized
    Description

    身份驗證失敗。請檢查您的 API 金鑰。

  • Name
    402 - Payment Required
    Description

    執行此任務所需的積分不足。

  • Name
    403 - Forbidden
    Description

    該 prompt 被內容 moderation 標記。

  • Name
    429 - Too Many Requests
    Description

    您已超出速率限制。

Request

POST
/openapi/v1/text-to-motion
# Generate a motion clip with required params only
curl https://api.meshy.ai/openapi/v1/text-to-motion \
  -X POST \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "a character waving",
    "duration": 3
  }'

# Generate a fast, economical clip with Swift mode
curl https://api.meshy.ai/openapi/v1/text-to-motion \
  -X POST \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "a character waving",
    "mode": "swift",
    "duration": 4.5
  }'

Response

{
  "result": "018c425b-b2c6-727e-d333-3c1887i9h791"
}

GET/openapi/v1/text-to-motion/:id

取得文本生成動作任務

此 endpoint 可讓您透過有效的任務 id 取得一個文本生成動作任務。請參閱文本生成動作任務物件以了解其中包含哪些屬性。

參數

  • Name
    id
    Type
    path
    Description

    要取得的文本生成動作任務的唯一識別碼。

回傳值

回應內容包含文本生成動作任務物件。詳情請參閱文本生成動作任務物件章節。

Request

GET
/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791
curl https://api.meshy.ai/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791 \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

Response

{
  "id": "018c425b-b2c6-727e-d333-3c1887i9h791",
  "type": "text-to-motion",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1787314497437,
  "started_at": 1787314498012,
  "finished_at": 1787314505881,
  "expires_at": 1787573705881,
  "task_error": null,
  "result": {
    "motion_url": "https://assets.meshy.ai/0630d47c-84b8-4d37-bc02-69e45d9272c1/tasks/018c425b-b2c6-727e-d333-3c1887i9h791/output/clip.fbx?Expires=...",
    "motion_format": "fbx",
    "duration_ms": 3000,
    "mode": "prime"
  },
  "consumed_credits": 10
}

GET/openapi/v1/text-to-motion

List Text to Motion Tasks

返回呼叫者的 Text to Motion 任務的分頁清單,依最新排序。透過 page_numpage_size 進行標準分頁。

回應是一個由Text to Motion Task 物件組成的陣列。

請注意,透過 API 建立的任務由 API 進行管理——它們不會出現在網頁應用程式的「我的資產」中。當你不再擁有某個任務的 ID 時,可使用此 endpoint 來查詢該任務。

Request

GET
/openapi/v1/text-to-motion
curl "https://api.meshy.ai/openapi/v1/text-to-motion?page_num=1&page_size=20" \
-H "Authorization: Bearer ${YOUR_API_KEY}"

Response

[
  {
    "id": "018c425b-b2c6-727e-d333-3c1887i9h791",
    "type": "text-to-motion",
    "status": "SUCCEEDED",
    "...": "..."
  }
]

GET/openapi/v1/text-to-motion/:id/stream

流式取得 Text to Motion 任務

此 endpoint 使用 Server-Sent Events(SSE)串流傳輸 Text to Motion 任務的即時更新。

參數

  • Name
    id
    Type
    path
    Description

    要進行串流傳輸的 Text to Motion 任務的唯一識別碼。

回傳

以 Server-Sent Events 的形式回傳 Text to Motion 任務物件 的串流。

每個 message 事件都攜帶完整的任務物件。當任務處於 PENDINGIN_PROGRESS 狀態時,result 欄位仍為空("" / 0),finished_at / expires_at0;請留意 statusprogress

Request

GET
/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791/stream
curl -N https://api.meshy.ai/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"

Response Stream

// Error event example
event: error
data: {
  "status_code": 404,
  "message": "Task not found"
}

// Message events carry the full task object at every stage; the result
// fields stay empty until the task succeeds.
event: message
data: {
  "id": "018c425b-b2c6-727e-d333-3c1887i9h791",
  "type": "text-to-motion",
  "status": "IN_PROGRESS",
  "progress": 50,
  "created_at": 1787314497437,
  "started_at": 1787314498012,
  "finished_at": 0,
  "expires_at": 0,
  "task_error": null,
  "result": {
    "motion_url": "",
    "motion_format": "",
    "duration_ms": 0,
    "mode": ""
  },
  "consumed_credits": 10
}

event: message
data: { // Example of a SUCCEEDED task stream item, mirroring The Text to Motion Task Object structure
  "id": "018c425b-b2c6-727e-d333-3c1887i9h791",
  "type": "text-to-motion",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1787314497437,
  "started_at": 1787314498012,
  "finished_at": 1787314505881,
  "expires_at": 1787573705881,
  "task_error": null,
  "result": {
    "motion_url": "https://assets.meshy.ai/.../output/clip.fbx?Expires=...",
    "motion_format": "fbx",
    "duration_ms": 3000,
    "mode": "prime"
  },
  "consumed_credits": 10
}

DELETE/openapi/v1/text-to-motion/:id

刪除 Text to Motion 任務

此 endpoint 將永久刪除一個 Text to Motion 任務,包括生成的動作片段。此操作不可逆。

路徑參數

  • Name
    id
    Type
    path
    Description

    要刪除的 Text to Motion 任務的 ID。

回傳

成功時回傳 200 OK

Request

DELETE
/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791
curl --request DELETE \
  --url https://api.meshy.ai/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791 \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

Response

// Returns 200 Ok on success.

Text to Motion 任務物件

Text to Motion 任務物件表示根據文字 prompt 生成動作片段的工作單元。

屬性

  • Name
    id
    Type
    string
    Description

    任務的唯一識別碼。

  • Name
    type
    Type
    string
    Description

    任務的類型。值為 text-to-motion

  • Name
    status
    Type
    string
    Description

    任務的狀態。可能的值:PENDINGIN_PROGRESSSUCCEEDEDFAILEDCANCELED

  • Name
    progress
    Type
    integer
    Description

    任務的進度(0-100)。

  • Name
    created_at
    Type
    timestamp
    Description

    任務建立時的時間戳(自紀元起的毫秒數)。

  • Name
    started_at
    Type
    timestamp
    Description

    任務開始處理時的時間戳(自紀元起的毫秒數)。如果尚未開始,則為 0

  • Name
    finished_at
    Type
    timestamp
    Description

    任務完成時的時間戳(自紀元起的毫秒數)。如果尚未完成,則為 0

  • Name
    expires_at
    Type
    timestamp
    Description

    任務結果資產過期時的時間戳(自紀元起的毫秒數)。在任務完成之前為 0。生成的片段在任務完成後保留 3 天,請在過期前下載。

  • Name
    preceding_tasks
    Type
    integer
    Description

    佇列中位於前面的任務數量。僅當狀態為 PENDING 時才有意義;為零時會省略此欄位。

  • Name
    consumed_credits
    Type
    integer
    Description

    此任務消耗的積分數量。prime mode 為 10swift mode 為 3。對於 FAILED 的任務會回傳 0(失敗時會退還積分)。

  • Name
    task_error
    Type
    object
    Description

    失敗任務的錯誤詳情;除非任務為 FAILED,否則為 null。完整的 task_error 物件參考請參閱 錯誤

  • Name
    result
    Type
    object
    Description

    任務 SUCCEEDED 後包含生成的動作片段;在此之前,這些欄位雖然存在但為空("" / 0)。

    • Name
      motion_url
      Type
      string
      Description
      生成的動作片段的可下載 URL。每次讀取時該 URL 都會重新簽署,並隨任務的保留期限一同過期。
    • Name
      motion_format
      Type
      string
      Description
      片段的檔案格式:prime mode 為 fbxswift mode 為 bvh
    • Name
      duration_ms
      Type
      integer
      Description
      生成的片段的時長(毫秒)。
    • Name
      mode
      Type
      string
      Description
      生成該片段所使用的 mode:primeswift

Example Text to Motion Task Object

{
  "id": "018c425b-b2c6-727e-d333-3c1887i9h791",
  "type": "text-to-motion",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1787314497437,
  "started_at": 1787314498012,
  "finished_at": 1787314505881,
  "expires_at": 1787573705881,
  "task_error": null,
  "result": {
    "motion_url": "https://assets.meshy.ai/.../output/clip.fbx?Expires=...",
    "motion_format": "fbx",
    "duration_ms": 3000,
    "mode": "prime"
  },
  "consumed_credits": 10
}