文本到動作 API
從自然語言描述生成角色動作剪輯。描述一個動作 — "角色揮手", "殭屍向前蹣跚" — 即可接收到一個原始動作剪輯,您可以在自己的管線或 DCC 工具中將其重新定位到已骨骼綁定的角色上。
輸出的是一個獨立的動作剪輯:它不需要,也不附加到角色模型上。要先對角色進行骨骼綁定,請參閱 骨骼綁定 API
建立文字到動作任務
這個endpoint可建立一個新任務,用於從文本prompt生成動作剪輯。
當mode為prime時,任務需花費10積分,並使用我們最高品質的動作模型進行生成。當mode為swift時,任務需花費3積分,並以更經濟的動作模型更快速生成。
參數
- Name
- prompt
- Type
- string
- 必選
- Description
要生成的動作的自然語言描述。最多400個字元。
- Name
- mode
- Type
- string
- 預設值 prime
- Description
動作生成模式。可用值:
prime,swift。prime生成最高品質並輸出FBX;swift速度更快且更經濟,並輸出BVH。
- Name
- duration
- Type
- number
- 必選
- Description
動作剪輯的目標持續時間,以秒為單位。介於
2和10之間,0.5為步長(例如2,2.5,3, …10)。
返回值
回應的result屬性包含新建立的文字到動作任務的任務id。
失敗模式
- Name
400 - Bad Request- Description
請求不可接受。常見原因:
- 缺少或空的prompt:
prompt缺失、為空或者超出400個字元。 - 無效的mode:
mode不是prime或swift。 - 無效的duration:
duration缺失、超出2到10範圍、或不在0.5秒步長上。
- 缺少或空的prompt:
- Name
401 - Unauthorized- Description
Authentication失敗。請檢查您的API key。
- Name
402 - Payment Required- Description
積分不足以執行此任務。
- Name
403 - Forbidden- Description
prompt被內容moderation標記。
- Name
429 - Too Many Requests- Description
您已超過速率限制。
請求
# 僅使用必需參數生成動作剪輯
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
}'
# 使用Swift模式生成快速經濟的剪輯
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
}'
回應
{
"result": "018c425b-b2c6-727e-d333-3c1887i9h791"
}
檢索文本到動作任務
這個endpoint允許您檢索指定有效任務id的文本到動作任務。請參閱文本到動作任務物件查看包含哪些屬性。
參數
- Name
- id
- Type
- path
- Description
要檢索的文本到動作任務的唯一標識符。
返回值
響應包含文本到動作任務物件。查看文本到動作任務物件部分了解詳情。
請求
curl https://api.meshy.ai/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
響應
{
"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
}
列出文本到動作任務
返回呼叫者的文本到動作任務的分頁列表,最新的在前。通過 page_num 和 page_size 進行標準分頁。
回應是一個文本到動作任務物件的陣列。
請注意,通過API建立的任務是通過API進行管理的——它們不會出現在Web App的「我的資產」中。使用此endpoint查找您不再擁有ID的任務。
請求
curl "https://api.meshy.ai/openapi/v1/text-to-motion?page_num=1&page_size=20" \
-H "Authorization: Bearer ${YOUR_API_KEY}"
回應
[
{
"id": "018c425b-b2c6-727e-d333-3c1887i9h791",
"type": "text-to-motion",
"status": "SUCCEEDED",
"...": "..."
}
]
流式傳輸文字到動作任務
此endpoint使用伺服器發送事件(SSE)流式傳輸文字到動作任務的即時更新。
參數
- Name
- id
- Type
- path
- Description
要傳輸的文字到動作任務的唯一標識符。
返回
以伺服器發送事件返回文字到動作任務對象的流。
每個message事件都攜帶完整的任務對象。在任務為PENDING或IN_PROGRESS時,result欄位仍然為空("" / 0),finished_at / expires_at為0;監控status和progress。
請求
curl -N https://api.meshy.ai/openapi/v1/text-to-motion/018c425b-b2c6-727e-d333-3c1887i9h791/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"
回應流
// 錯誤事件範例
event: error
data: {
"status_code": 404,
"message": "任務未找到"
}
// 訊息事件在每個階段傳遞完整的任務對象;結果欄位在任務成功之前保持空白。
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: { // SUCCEEDED任務流項目的範例,鏡像文字到動作任務對象結構
"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
}
刪除文字轉動作任務
此endpoint永久刪除一個文字轉動作任務,包括生成的動作剪輯。此操作不可逆。
路徑參數
- Name
- id
- Type
- path
- Description
要刪除的文字轉動作任務的ID。
返回值
成功時返回 200 OK。
Request
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
// 成功時返回200 Ok。
文本到動作任務物件
文本到動作任務物件表示從文本提示生成動作片段的工作單元。
屬性
- Name
- id
- Type
- string
- Description
任務的唯一標識符。
- Name
- type
- Type
- string
- Description
任務的類型。值為
text-to-motion。
- Name
- status
- Type
- string
- Description
任務的狀態。可能的值:
PENDING、IN_PROGRESS、SUCCEEDED、FAILED、CANCELED。
- Name
- progress
- Type
- integer
- Description
任務的進度(0-100)。
- Name
- created_at
- Type
- timestamp
- Description
創建任務時的時間戳(自紀元以來的毫秒數)。
時間戳表示自 1970 年 1 月 1 日 UTC 起經過的毫秒數,遵循 RFC 3339
標準。 例如,2023 年 9 月 1 日星期五,GMT 時間中午 12:00:00 表示為1693569600000。 這適用於 Meshy API 中的所有時間戳。
- 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模式為10,swift模式為3。對於FAILED任務返回0(失敗時積分會被退還)。
- Name
- task_error
- Type
- object
- Description
失敗任務的錯誤詳情;除非任務
FAILED,否則為null。詳見完整的 Errors 中的task_error物件參考。
- Name
- result
- Type
- object
- Description
一旦任務
SUCCEEDED,包含生成的動作片段;在此之前欄位存在但為空 (""/0)。- Name
motion_url- Type
- string
- Description
- 下載生成的動作片段的 URL。URL 每次讀取都會重新簽名,並在任務的保留窗口到期時失效。
- Name
motion_format- Type
- string
- Description
- 片段的文件格式:
fbx對於prime模式,bvh對於swift模式。
- Name
duration_ms- Type
- integer
- Description
- 生成的片段的持續時間,單位為毫秒。
- Name
mode- Type
- string
- Description
- 片段生成時使用的模式:
prime或swift。
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
}