尺寸調整 API

尺寸調整 API 讓您可以將現有的 3D 模型調整為真實世界的尺寸。您可以指定精確的高度、最長邊約束,或讓 AI 自動估算合適的尺寸。


POST/openapi/v1/resize

建立尺寸調整任務

此 endpoint 用於建立一個新的尺寸調整任務。

參數

  • Name
    input_task_id
    Type
    string
    必選
    Description

    您希望調整尺寸的模型所對應的已完成 Meshy 任務的 ID。 該任務的狀態必須為 SUCCEEDED。 輸出格式將為 GLB。

  • Name
    model_url
    Type
    string
    必選
    Description

    指向 3D 模型檔案的可公開存取的 URL 或 data URI。 支援的格式:.glb、.gltf、.obj、.fbx、.stl。 對於 Data URI,請使用 MIME type:application/octet-stream。 輸出格式將保留輸入模型的原始格式。

  • Name
    resize_height
    Type
    number
    Description

    將模型調整為以公尺為單位的特定高度。

  • Name
    resize_longest_side
    Type
    number
    Description

    調整模型尺寸,使其最長邊符合此數值(以公尺為單位)。系統會維持長寬比不變。

  • Name
    auto_size
    Type
    boolean
    Description

    設為 true 時,服務會使用 AI 視覺自動估算物體的真實世界高度,並依此調整模型尺寸。除非明確設定 origin_at,否則 origin 將預設為 bottom。

  • Name
    origin_at
    Type
    string
    預設值 bottom
    Description

    調整尺寸後 origin 的位置。

    可用值:bottom、center。

回傳值

回應的 result 屬性包含新建立的尺寸調整任務的 id。

失敗模式

  • 400 - Bad Request

請求無法被接受。常見原因:

  • 缺少參數:必須提供 model_url 或 input_task_id 其中之一。
  • 缺少尺寸調整 mode:必須指定 resize_height、resize_longest_side 或 auto_size 中的至少一個。
  • 互斥參數:resize_height、resize_longest_side 和 auto_size 不能同時使用。
  • 輸入任務無效:input_task_id 必須指向一個成功的任務。
  • 模型格式無效:model_url 指向的檔案副檔名不受支援。
  • URL 無法存取:無法下載 model_url 指向的檔案。
  • 401 - Unauthorized

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

  • 402 - Payment Required

積分不足,無法執行此任務。

  • 429 - Too Many Requests

您已超出速率限制。

Request

POST
/openapi/v1/resize
# Simple: resize to a specific height
curl https://api.meshy.ai/openapi/v1/resize \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
    "input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "resize_height": 1.8
  }'

# Advanced: resize longest side with custom origin
curl https://api.meshy.ai/openapi/v1/resize \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
    "model_url": "https://example.com/model.glb",
    "resize_longest_side": 2.0,
    "origin_at": "center"
  }'

Response

{
  "result": "0193bfc5-ee4f-73f8-8525-44b398884ce9"
}

GET/openapi/v1/resize/:id

取得尺寸調整任務

此 endpoint 用於根據 ID 取得一個尺寸調整任務。

參數

  • Name
    id
    Type
    path
    Description

    要取得的尺寸調整任務的 ID。

返回值

尺寸調整任務物件。

Request

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

Response

{
  "id": "0193bfc5-ee4f-73f8-8525-44b398884ce9",
  "type": "resize",
  "model_urls": {
      "glb": "https://assets.meshy.ai/.../model.glb?Expires=..."
  },
  "progress": 100,
  "status": "SUCCEEDED",
  "created_at": 1699999999000,
  "started_at": 1700000000000,
  "finished_at": 1700000001000,
  "task_error": null,
  "consumed_credits": 1
}

DELETE/openapi/v1/resize/:id

刪除尺寸調整任務

此 endpoint 將永久刪除一個尺寸調整任務,包括所有相關的模型和資料。此操作不可逆。

路徑參數

  • Name
    id
    Type
    path
    Description

    要刪除的尺寸調整任務的 ID。

任務狀態

仍處於 PENDING 狀態的任務被刪除後,建立時消耗的 credits 會被退還。

已處於 IN_PROGRESS 狀態的任務無法刪除:請求會被拒絕並返回 409 Conflict,任務將繼續執行。工作處理程序已經開始處理的任務所消耗的 credits 不可退還,因此在執行過程中刪除該任務將同時損失 credits 和結果。請等待任務達到 SUCCEEDED、FAILED 或 CANCELED 狀態後再刪除。

處於終止狀態(SUCCEEDED、FAILED 或 CANCELED)的任務被刪除時不會退還 credits。

返回值

成功時返回 200 OK;當任務處於 IN_PROGRESS 狀態時返回 409 Conflict。

Request

DELETE
/openapi/v1/resize/:id
curl --request DELETE \
  --url https://api.meshy.ai/openapi/v1/resize/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."
}

GET/openapi/v1/resize

取得尺寸調整任務列表

此 endpoint 允許您取得尺寸調整任務列表。

參數

  • 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:依建立時間降冪排列。

返回值

返回 尺寸調整任務物件 的分頁列表。

Request

GET
/openapi/v1/resize
curl https://api.meshy.ai/openapi/v1/resize?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"

Response

[
  {
    "id": "0193bfc5-ee4f-73f8-8525-44b398884ce9",
    "type": "resize",
    "model_urls": {
      "glb": "https://assets.meshy.ai/.../model.glb?Expires=..."
    },
    "progress": 100,
    "status": "SUCCEEDED",
    "created_at": 1699999999000,
    "started_at": 1700000000000,
    "finished_at": 1700000001000,
    "task_error": null,
    "consumed_credits": 1
  }
]

GET/openapi/v1/resize/:id/stream

流式取得尺寸調整任務

此 endpoint 使用伺服器推送事件(SSE)為尺寸調整任務串流傳輸即時更新。

參數

  • Name
    id
    Type
    path
    Description

    要串流傳輸的尺寸調整任務的唯一識別碼。

回傳

以 Server-Sent Events 的形式回傳 尺寸調整任務物件 的串流。

對於狀態為 PENDING 或 IN_PROGRESS 的任務,回應串流中只會包含必要的 progress 和 status 欄位。

Request

GET
/openapi/v1/resize/:id/stream
curl -N https://api.meshy.ai/openapi/v1/resize/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": "resize",
  "model_urls": {
    "glb": "https://assets.meshy.ai/.../model.glb?Expires=..."
  },
  "progress": 100,
  "status": "SUCCEEDED",
  "created_at": 1699999999000,
  "started_at": 1700000000000,
  "finished_at": 1700000001000,
  "task_error": null,
  "consumed_credits": 1
}

尺寸調整任務物件

尺寸調整任務物件表示一個尺寸調整作業。

屬性

  • id · string

任務的唯一識別碼。

  • type · string

任務的類型。此值為 resize。

  • model_urls · object

調整尺寸後模型檔案的可下載 URL。使用 input_task_id 時,輸出始終為 GLB。使用 model_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

任務失敗時的錯誤物件。有關更多詳情,請參閱錯誤。

  • consumed_credits · integer

此任務消耗的積分數量(每個尺寸調整任務消耗 1 積分)。對於 FAILED 的任務,返回 0。