Convert API

格式轉換 API 讓您能夠將現有的 3D 模型轉換為不同的檔案格式。


POST/openapi/v1/convert

建立 Convert 任務

此端點用於建立一個新的格式轉換任務。

參數

  • 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

    轉換後模型的輸出格式清單。 可用值:glbfbxobjusdzblendstl3mf

回傳值

回應中的 result 屬性包含新建立的 convert 任務的 id

失敗模式

  • 400 - Bad Request

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

  • 缺少參數:必須提供 model_urlinput_task_id 中的一個。
  • 缺少 target_formats:必須至少指定一種目標格式。
  • 輸入任務無效input_task_id 必須指向一個成功的任務。
  • 模型格式無效model_url 指向的檔案副檔名不受支援。
  • URL 無法存取:無法下載 model_url 指向的檔案。
  • 401 - Unauthorized

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

  • 402 - Payment Required

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

  • 429 - Too Many Requests

您已超出速率限制。

Request

POST
/openapi/v1/convert
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"
}

GET/openapi/v1/convert/:id

獲取 Convert 任務

此 endpoint 根據 ID 獲取一個 convert 任務。

參數

  • Name
    id
    Type
    path
    Description

    要獲取的 convert 任務的 ID。

返回值

Convert Task 物件。

Request

GET
/openapi/v1/convert/:id
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
}

DELETE/openapi/v1/convert/:id

刪除 Convert 任務

此端點將永久刪除一個 convert 任務,包括所有關聯的模型與資料。此操作無法復原。

路徑參數

  • Name
    id
    Type
    path
    Description

    要刪除的 convert 任務的 ID。

回傳值

成功時回傳 200 OK

Request

DELETE
/openapi/v1/convert/:id
curl --request DELETE \
  --url https://api.meshy.ai/openapi/v1/convert/a43b5c6d-7e8f-901a-234b-567c890d1e2f \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

Response

// Returns 200 Ok on success.

GET/openapi/v1/convert

列出 Convert 任務

此 endpoint 允許您檢索 convert 任務列表。

參數

  • Name
    page_num
    Type
    integer
    預設值 1
    Description

    用於分頁的頁碼。

  • Name
    page_size
    Type
    integer
    預設值 10
    Description

    每頁數量限制。最多允許 50 個。

  • Name
    sort_by
    Type
    string
    Description

    用於排序的欄位。 可用值:

    • +created_at:依建立時間升冪排序。
    • -created_at:依建立時間降冪排序。

回傳值

回傳一個分頁的 Convert 任務物件 清單。

Request

GET
/openapi/v1/convert
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
  }
]

GET/openapi/v1/convert/:id/stream

流式取得 Convert 任務

此 endpoint 使用 Server-Sent Events (SSE) 以串流方式傳輸 convert 任務的即時更新。

參數

  • Name
    id
    Type
    path
    Description

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

回傳

以 Server-Sent Events 的形式回傳一個 Convert 任務物件 串流。

對於處於 PENDINGIN_PROGRESS 狀態的任務,回應串流中只會包含必要的 progressstatus 欄位。

Request

GET
/openapi/v1/convert/:id/stream
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 任務物件

Convert 任務物件表示一個格式轉換作業。

屬性

  • id · string

任務的唯一識別碼。

  • type · string

任務的類型。此值為 convert

  • model_urls · object

格式轉換後模型檔案的可下載 URL。只有 target_formats 中指定的格式才會有對應的 URL。其他格式屬性將為空字串。

  • progress · integer

任務的 progress(0-100)。

  • status · string

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

  • preceding_tasks · integer

排在前面的任務數量。僅當狀態為 PENDING 時有意義。

  • created_at · timestamp

任務建立時間的時間戳,單位為毫秒。

  • started_at · timestamp

任務開始時間的時間戳,單位為毫秒。如果尚未開始,則為 0

  • finished_at · timestamp

任務完成時間的時間戳,單位為毫秒。如果尚未完成,則為 0

  • task_error · object

任務失敗時的錯誤物件。更多詳情請參見 Errors

  • consumed_credits · integer

此任務消耗的積分數量(每個轉換任務消耗 1 個積分)。對於 FAILED 任務,回傳 0