Convert API
Convert API 讓您可以將現有的 3D 模型進行格式轉換,轉換為不同的檔案格式。
建立 Convert 任務
此端點用於建立一個新的格式轉換任務。
參數
input_task_id 和 model_url 中只需提供一個,即為必填。如果兩者都提供,則 input_task_id 具有更高優先順序。
- Name
- input_task_id
- Type
- string
- 必選
- Description
您希望轉換其模型的已完成 Meshy 任務的 ID。 該任務的狀態必須為
SUCCEEDED。
- Name
- model_url
- Type
- string
- 必選
- Description
指向 3D 模型檔案的可公開存取的 URL 或 data URI。 支援的格式:
.glb、.gltf、.obj、.fbx、.stl。 對於 Data URI,請使用 MIME type:application/octet-stream。
- Name
- target_formats
- Type
- string[]
- 必選
- Description
轉換後模型的輸出格式清單。 可用值:
glb、fbx、obj、usdz、blend、stl、3mf。
回傳值
回應中的 result 屬性包含新建立的 convert 任務的 id。
失敗模式
400 - Bad Request
請求不可接受。常見原因:
- 缺少參數:必須提供
model_url或input_task_id之一。 - 缺少 target_formats:必須指定至少一種目標格式。
- 輸入任務無效:
input_task_id必須引用一個成功的任務。 - 模型格式無效:
model_url指向的檔案副檔名不受支援。 - URL 無法存取:無法下載
model_url指向的檔案。
401 - Unauthorized
身份驗證失敗。請檢查您的 API 金鑰。
402 - Payment Required
積分不足,無法執行此任務。
429 - Too Many Requests
您已超出速率限制。
Request
curl https://api.meshy.ai/openapi/v1/convert \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"target_formats": ["fbx", "stl"]
}'
Response
{
"result": "0193bfc5-ee4f-73f8-8525-44b398884ce9"
}
檢索一個 Convert 任務
此端點用於根據 ID 檢索一個格式轉換任務。
參數
- Name
- id
- Type
- path
- Description
要檢索的格式轉換任務的 ID。
返回值
Convert Task 物件。
Request
curl https://api.meshy.ai/openapi/v1/convert/a43b5c6d-7e8f-901a-234b-567c890d1e2f \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
{
"id": "0193bfc5-ee4f-73f8-8525-44b398884ce9",
"type": "convert",
"model_urls": {
"glb": "",
"fbx": "https://assets.meshy.ai/.../model.fbx?Expires=...",
"obj": "",
"usdz": "",
"stl": "https://assets.meshy.ai/.../model.stl?Expires=..."
},
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000001000,
"task_error": null,
"consumed_credits": 1
}
刪除一個 Convert 任務
此 endpoint 會永久刪除一個 convert 任務,包括所有關聯的模型和資料。此操作不可撤銷。
路徑參數
- Name
- id
- Type
- path
- Description
要刪除的 convert 任務的 ID。
任務狀態
仍處於 PENDING 狀態的任務會被刪除,並且建立時消耗的 credits 會被退還。
已處於 IN_PROGRESS 狀態的任務無法被刪除:請求會被拒絕,並返回 409 Conflict,任務會繼續執行。工作處理程序(worker)已經開始處理的任務,其 credits 是不可退還的,因此在執行過程中刪除該任務會使你同時失去 credits 和結果。請等待任務到達 SUCCEEDED、FAILED 或 CANCELED 狀態後再刪除。
處於終止狀態(SUCCEEDED、FAILED 或 CANCELED)的任務在刪除時不會退還 credits。
回傳值
成功時回傳 200 OK;當任務處於 IN_PROGRESS 狀態時回傳 409 Conflict。
Request
curl --request DELETE \
--url https://api.meshy.ai/openapi/v1/convert/a43b5c6d-7e8f-901a-234b-567c890d1e2f \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
// 200 OK on success, with an empty body.
//
// 409 Conflict when the task is IN_PROGRESS — the task is left running:
{
"message": "Task is IN_PROGRESS and cannot be deleted. Credits for a task the worker has already started are not refundable; wait for it to reach SUCCEEDED, FAILED or CANCELED, then delete it."
}
List Convert Tasks
此端點允許您檢索 convert 任務列表。
參數
- Name
- page_num
- Type
- integer
- 預設值 1
- Description
用於分頁的頁碼。
- Name
- page_size
- Type
- integer
- 預設值 10
- Description
分頁大小限制。最大允許
100項。
- Name
- sort_by
- Type
- string
- Description
用於排序的欄位。 可用值:
+created_at:按建立時間升序排序。-created_at:按建立時間降序排序。
回傳值
回傳 Convert 任務物件的分頁列表。
Request
curl https://api.meshy.ai/openapi/v1/convert?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
[
{
"id": "0193bfc5-ee4f-73f8-8525-44b398884ce9",
"type": "convert",
"model_urls": {
"fbx": "https://assets.meshy.ai/.../model.fbx?Expires=...",
"stl": "https://assets.meshy.ai/.../model.stl?Expires=..."
},
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000001000,
"task_error": null,
"consumed_credits": 1
}
]
流式取得格式轉換任務
此 endpoint 使用伺服器發送事件(Server-Sent Events,SSE)串流傳輸格式轉換任務的即時更新。
參數
- Name
- id
- Type
- path
- Description
要進行串流傳輸的格式轉換任務的唯一識別碼。
回傳值
以 Server-Sent Events 的形式回傳 格式轉換任務物件 的串流。
對於 PENDING 或 IN_PROGRESS 狀態的任務,回應串流中只會包含必要的 progress 和 status 欄位。
Request
curl -N https://api.meshy.ai/openapi/v1/convert/a43b5c6d-7e8f-901a-234b-567c890d1e2f/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response Stream
// Message event examples illustrate task progress.
event: message
data: {
"id": "0193bfc5-ee4f-73f8-8525-44b398884ce9",
"progress": 0,
"status": "PENDING"
}
event: message
data: {
"id": "0193bfc5-ee4f-73f8-8525-44b398884ce9",
"type": "convert",
"model_urls": {
"fbx": "https://assets.meshy.ai/.../model.fbx?Expires=...",
"stl": "https://assets.meshy.ai/.../model.stl?Expires=..."
},
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000001000,
"task_error": null,
"consumed_credits": 1
}
Convert Task 物件
Convert Task 物件表示一個格式轉換任務。
屬性
id· string
任務的唯一識別碼。
type· string
任務的類型。該值為 convert。
model_urls· object
轉換後模型檔案的可下載 URL。僅 target_formats 中指定的格式會有對應的 URL。其他格式屬性將為空字串。
progress· integer
任務的 progress(0-100)。
status· string
任務的狀態。可能的取值:PENDING、IN_PROGRESS、SUCCEEDED、FAILED、CANCELED。
preceding_tasks· integer
排在前面的任務數量。僅當狀態為 PENDING 時才有意義。
created_at· timestamp
任務建立時的時間戳,單位為毫秒。
started_at· timestamp
任務開始時的時間戳,單位為毫秒。若尚未開始,則為 0。
finished_at· timestamp
任務完成時的時間戳,單位為毫秒。若尚未完成,則為 0。
task_error· object
任務失敗時的錯誤物件。更多詳情請參見 Errors。
consumed_credits· integer
此任務消耗的 積分 數量(每個 convert 任務消耗 1 credit)。若任務為 FAILED,則返回 0。