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

执行此任务所需的 credits 不足。

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

此 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 任务对象 列表。

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

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

此任务消耗的 credits 数量(每个转换任务消耗 1 个 credit)。对于 FAILED 任务,返回 0