Convert API

Convert API 允许您将现有的 3D 模型转换为不同的文件格式。


POST/openapi/v1/convert

创建一个 Convert 任务

此 endpoint 创建一个新的格式转换任务。

参数

  • 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

authentication 失败。请检查您的 API key。

  • 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

检索转换任务

此endpoint通过其ID检索转换任务。

参数

  • Name
    id
    Type
    path
    Description

    要检索的转换任务的ID。

返回

转换任务对象。

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 任务

此 endpoint 会永久删除一个 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 任务对象 列表。

请求

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

响应

[
  {
    "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 使用服务器发送事件 (SSE) 流式传输 Convert 任务的实时更新。

参数

  • Name
    id
    Type
    path
    Description

    要流式传输的 Convert 任务的唯一标识符。

返回值

返回 Convert 任务对象 的流作为服务器发送事件。

对于 PENDINGIN_PROGRESS 任务,响应流将仅包含必要的 progressstatus 字段。

请求

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}"

响应流

// 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

任务的进度(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