任务
通过 /openapi/v2/tasks 下的四个路由获取、列出、流式传输和删除每个 v2 任务。每个创建任务的 v2 endpoint 都会返回相同的任务对象。
从 v1 迁移?读取任务的主要变化:
- 本页中的路由取代了各 endpoint 专属的读取路由,例如
GET /openapi/v1/image-to-3d/{id}。 - 结果位于
output中。
请参阅迁移参考中的任务读取。
任务对象
你可以从以下地方获取该对象:
- 创建响应
GET /openapi/v2/tasks/{id}- 列表中的每一项
- 每个流式传输事件
- 每次 v2 webhook 投递
只有 input 和 output 取决于任务类型。
A task in progress
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "image-to-3d",
"status": "IN_PROGRESS",
"progress": 42,
"created_at": 1791846275575,
"started_at": 1791846275578,
"finished_at": null,
"expires_at": null,
"preceding_tasks": 0,
"consumed_credits": 30,
"task_error": null,
"input": {
"image_url": "https://docs.meshy.ai/images/api/quick-start/source-photo.webp",
"texture_model": "meshy-7"
},
"output": null
}
A succeeded task
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "image-to-3d",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1791846275575,
"started_at": 1791846275578,
"finished_at": 1791846334536,
"expires_at": 1792105534536,
"preceding_tasks": 0,
"consumed_credits": 30,
"task_error": null,
"input": {
"image_url": "https://docs.meshy.ai/images/api/quick-start/source-photo.webp",
"texture_model": "meshy-7"
},
"output": {
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***"
},
"thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
"thumbnail_urls": null,
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
"metallic": null,
"roughness": null,
"normal": null,
"metallic_roughness": null,
"emission": null
}
]
}
}
A failed task
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "convert",
"status": "FAILED",
"progress": 0,
"created_at": 1790911760868,
"started_at": 1790911760873,
"finished_at": 1790911770684,
"expires_at": null,
"preceding_tasks": 0,
"consumed_credits": 0,
"task_error": {
"type": "invalid_input",
"code": "invalid_input",
"message": "No valid objects found in uploaded model. The file may be empty or contain no importable geometry.",
"doc_url": "https://docs.meshy.ai/en/api/v2/errors#invalid-input"
},
"input": {
"model_url": "https://example.com/model.glb",
"target_formats": ["fbx"]
},
"output": null
}
- Name
- id
- Type
- string
- Description
任务 ID。在本页面的路由中使用它。
- Name
- type
- Type
- string
- Description
任务类型,由创建该任务的 endpoint 设置。参见任务类型。Meshy 会为每个新 endpoint 添加一个类型,因此请跳过或记录你代码未处理的类型。
- Name
- status
- Type
- string
- Description
任务的状态。参见任务如何运行。
可用值:
PENDING:正在队列中等待IN_PROGRESS:正在生成结果SUCCEEDED:终态,结果在output中FAILED:终态,原因在task_error中CANCELED:终态,没有结果
- Name
- progress
- Type
- integer
- Description
已完成工作的百分比,取值从
0到100。任务成功时为100。
- Name
- created_at
- Type
- integer
- Description
任务的创建时间,以 Unix 毫秒表示。
- Name
- started_at
- Type
- integer | null
- Description
工作进程开始处理任务的时间,以 Unix 毫秒表示。在此之前为
null。
- Name
- finished_at
- Type
- integer | null
- Description
任务达到终态的时间,以 Unix 毫秒表示。在此之前为
null。
- Name
- expires_at
- Type
- integer | null
- Description
output中签名 URL 失效的时间,以 Unix 毫秒表示。它是finished_at之后的 3 天。在任务成功之前为
null。对于 Text to 3D 任务,以及会无限期保留文件的企业版计划,始终为null。参见资产保留期。
- Name
- preceding_tasks
- Type
- integer
- Description
任务处于
PENDING状态时在队列中的位置。1表示下一个开始执行。任务离开队列后为0,在列表结果中始终为0。
- Name
- consumed_credits
- Type
- integer | null
- Description
该任务扣除的积分数量(已计入任何退款)。失败任务为
0。如果 Meshy 无法读取扣费信息,则为null。此时请重新获取该任务。
- Name
- task_error
- Type
- object | null
- Description
任务失败的原因,包含以下字段:
typecodemessagedoc_url
除非
status为FAILED,否则为null。参见 Errors。
- Name
- input
- Type
- object | null
- Description
你在创建任务时发送的 参数,与你发送时的内容一致。Meshy 不会补全你省略的默认值,并且会省略该 endpoint 不接受的键。
如果你以 Data URI 形式发送的图片,返回时会变为指向 Meshy 副本的签名 URL;若没有副本,则会被截短。在 v1 上创建的任务会保留其 v1 参数名称。
当 Meshy 没有保存该请求的副本时为
null。这种情况会出现在任务刚创建后的短暂时间内,以及部分较旧的任务中。
- Name
- output
- Type
- object | null
- Description
结果,其结构由
type决定。在任务成功之前为null。每个 endpoint 页面都会描述其输出,任务类型中列出了相应字段。
上述列表中的每个字段始终存在。尚不存在的值为 null,绝不会是 0 或 "",数组也绝不会是 null,但 intended_print 对象中的 dimensions_mm 除外。
有两种任务类型可能会多出一个顶层字段:
- Auto Split 可能会添加
prompt_ignored。 - 可打印性修复会为所有在 v2 上创建的任务添加
intended_print。
Meshy 可能随时添加新字段,因此请忽略你未使用的字段。
任务类型
type 字段以及 List tasks 中的 type 过滤器使用以下值。每个 endpoint 页面都会详细描述其 output。
type | 创建方式 | output 字段 |
|---|---|---|
text-to-3d-preview | Text to 3D,preview | model_urls、thumbnail_url、alpha_thumbnail_url、texture_urls |
text-to-3d-refine | Text to 3D,refine | model_urls、thumbnail_url、alpha_thumbnail_url、texture_urls |
text-to-3d | Text to 3D,一次调用完成 | model_urls、thumbnail_url、alpha_thumbnail_url、texture_urls |
image-to-3d | Image to 3D | model_urls、thumbnail_url、thumbnail_urls、texture_urls |
multi-image-to-3d | Multi-Image to 3D | model_urls、thumbnail_url、thumbnail_urls、texture_urls |
remesh | Remesh | model_urls、thumbnail_url、texture_urls |
convert | Convert | model_urls、texture_urls |
resize | Resize | model_urls、texture_urls |
uv-unwrap | UV Unwrap | model_urls、thumbnail_url |
rig | Rigging | rigged_character_glb_url、rigged_character_fbx_url、basic_animations |
rig-check | Rigging Check | riggable、animation_type、animatable、reasons |
animate | Animation | animation_glb_url、animation_fbx_url、processed_usdz_url、processed_armature_fbx_url、processed_animation_fps_fbx_url |
text-to-motion | Text to Motion | motion_url、motion_format、duration_ms、mode |
retexture | Retexture | model_urls、thumbnail_url、texture_urls |
text-to-image | Text to Image | image_urls |
image-to-image | Image to Image | image_urls |
print-multi-color | Multi-Color Print | model_urls |
print-analyze | Analyze Printability | printability |
print-repair | Repair Printability | model_urls、thumbnail_url、print_repair_report |
print-split | Auto Split | model_urls、thumbnail_url、part_count |
relief | Relief | model_urls、texture_urls、depth_map_url、thumbnail_url |
以下几条规则适用于所有类型:
model_urls为任务生成的每种文件格式提供一个键,例如glb或fbx。任务未生成的格式则不会出现对应的键。texture_urls中的每一项都包含以下全部六种贴图,若任务未生成某种贴图,其值为null:base_colormetallicroughnessnormalmetallic_roughnessemission
- 每个 URL 都经过签名,并在
expires_at后失效。请在此之前下载所需文件。参见 Asset retention。
Creative Lab 任务不属于 API v2,因此不会出现在这些路由中。请通过它们专属的 Creative Lab 路由来获取。
任务如何运行
创建请求会立即返回任务对象,而不会等待任务运行。任务随后会在后台运行。要跟踪任务,可以使用以下方式之一:
PENDING 状态启动一个任务。worker 会接手处理,任务随之进入 IN_PROGRESS 状态,这也是任务耗时最长的阶段。任务最终会以 SUCCEEDED 或 FAILED 结束,终态永远不会再改变。PENDINGIN_PROGRESSSUCCEEDEDoutput 中的文件FAILED下表展示了在每种状态下你的代码应该执行的操作。
| 状态 | 你的代码应执行的操作 |
|---|---|
PENDING | 继续等待。preceding_tasks 表示任务在队列中的位置,1 表示该任务是下一个即将开始的。 |
IN_PROGRESS | 继续等待。progress 表示已完成工作的百分比。 |
SUCCEEDED | 在 expires_at 之前下载 output 中的文件。 |
FAILED | 读取 task_error,然后修正输入或创建另一个任务。请参阅 Errors。 |
CANCELED | 停止等待。该任务不会产生结果。目前没有任何 v2 任务类型会使用此状态,但应将其视为终态处理。 |
从你的代码角度看,整个流程如下所示:
请求: POST/image-to-3d
响应: 202{ "id": "<task_id>","status": "PENDING" }Location: /tasks/<task_id>任务已创建
- 等待
Retry-After秒后重复请求: GET/tasks/<task_id>
响应: 200{ "status": "IN_PROGRESS","progress": 45 }Retry-After: 5
请求: GET/tasks/<task_id>
响应: 200{ "status": "SUCCEEDED","output": { "model_urls": { "glb": "…" } } }
有两个响应头可以帮助你跟踪任务:
Location:读取任务的路径,即/openapi/v2/tasks/{id}。该响应头出现在创建请求的响应中。Retry-After:表示在下一次轮询前应等待的秒数。该响应头出现在创建请求的响应中,以及每次读取处于PENDING或IN_PROGRESS状态任务的响应中。该值只是一个参考值,当任务即将开始或完成时,这个值会更短。已经完成的任务不会带有Retry-After,例如当可打印性分析直接返回缓存结果时就是如此。如果响应头缺失,请等待 5 秒。轮询请求也会计入你的速率限制。
关于典型的处理时间,以及你的代码在放弃等待之前应该等待多久,请参阅处理时间。即使你的代码停止等待,任务仍会继续运行。
如果想通过通知的方式获取结果而不是轮询,可以在 Webhooks 页面中设置 Payload 版本为 v2 的 webhook。每次投递都会携带该任务对象,并带有请求头 Meshy-Webhook-Version: v2。详见 Webhooks。
获取任务
返回任意类型的一个任务,包括你在 v1 上创建的任务。Creative Lab 任务在此处不可用。
当任务处于 PENDING 或 IN_PROGRESS 状态时,Retry-After 响应头会告诉你在再次获取该任务之前需要等待多少秒。
Request
# Get one task by its ID
curl https://api.meshy.ai/openapi/v2/tasks/018a210d-8ba4-705c-b111-1f1776f7f578 \
-H "Authorization: Bearer ${MESHY_API_KEY}"
Response headers
HTTP/2 200
Content-Type: application/json; charset=utf-8
Retry-After: 5
List tasks
返回您的任务,默认按最新排序。
Request
# List your two newest Image to 3D tasks
curl "https://api.meshy.ai/openapi/v2/tasks?type=image-to-3d&page_size=2" \
-H "Authorization: Bearer ${MESHY_API_KEY}"
Response (task objects shortened)
{
"data": [
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "image-to-3d",
"status": "SUCCEEDED",
"progress": 100,
"...": "..."
},
{
"id": "018a2110-7a91-7c2e-9b10-5d6e7f8a9b0c",
"type": "image-to-3d",
"status": "IN_PROGRESS",
"progress": 42,
"...": "..."
}
],
"has_more": true
}
参数
- Name
- type
- Type
- string
- Description
要列出的任务类型。
text-to-3d匹配所有三种 Text to 3D 类型。留空则列出所有类型的任务。
- Name
- page_num
- Type
- integer
- 默认值 1
- Description
要返回的页码,从
1到255。0返回第一页。超出0到255范围的值会返回400。
- Name
- page_size
- Type
- integer
- 默认值 10
- Description
每页的任务数量,最多
100。101到255之间的值会返回 100 个任务,0则使用默认值。超出0到255范围的值会返回400。
- Name
- sort_by
- Type
- string
- 默认值 -created_at
- Description
排序方式。
可选值:
-created_at:最新优先+created_at:最早优先
Returns
一个包含两个字段的对象:
- Name
- data
- Type
- array
- Description
本页的任务,每个都是完整的任务对象。没有任务时为空数组,绝不会是
null。
- Name
- has_more
- Type
- boolean
- Description
是否还有下一页。若为
true,请用page_num加一来请求下一页。最后一页时为false。
响应中不包含总数。
Errors
- Name
400 - Bad Request- Description
以下某个查询参数无效:
type不是已知的任务类型。错误信息中会列出有效值。page_num或page_size不是0到255之间的整数。sort_by不是-created_at或+created_at。
修正该参数后重新发送请求。
流式获取任务更新
以 Server-Sent Events 的形式流式传输任务的更新,直到任务到达最终状态。
Request
# Stream a task's updates until it finishes
curl -N https://api.meshy.ai/openapi/v2/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/stream \
-H "Authorization: Bearer ${MESHY_API_KEY}"
Events (task objects shortened)
event:message
data:{"id":"018a210d-8ba4-705c-b111-1f1776f7f578","type":"image-to-3d","status":"IN_PROGRESS","progress":42,...}
event:message
data:{"id":"018a210d-8ba4-705c-b111-1f1776f7f578","type":"image-to-3d","status":"SUCCEEDED","progress":100,...,"output":{"model_urls":{"glb":"..."},...}}
参数
- Name
- id
- Type
- path
- 必选
- Description
创建响应中返回的任务 ID。
返回值
一个 text/event-stream,包含两种事件:
- Name
message- Description
完整的任务对象。第一个事件会立即到达,之后每当任务发生变化时都会再次发送。Meshy 还会每 10 秒重复发送最新状态,因此即使连接处于静默状态也会收到事件。流会在带有最终状态的事件之后关闭。
- Name
error- Description
error 对象,外加
status_code。例如,{"type": "not_found", "code": "task_not_found", "message": "Task not found", "doc_url": "https://docs.meshy.ai/en/api/v2/asset-retention", "status_code": 404}。流会在此事件之后关闭。流打开后,HTTP 状态码会一直保持
200,因此需要从事件中读取错误信息。而在流打开之前发生的错误,例如缺少 API key,则是普通的 HTTP 错误。
流会在大约 21 分钟后关闭,即使任务尚未完成。网络中断可能会导致流更早关闭。如果流在没有最终状态的情况下关闭,请重新打开它,或获取任务。
删除任务
删除任意类型的任务。删除操作无法撤销,已删除的任务在所有路由上都会返回 404。Creative Lab 任务无法在此处删除,会像 获取任务 中一样返回 404。
删除一个 PENDING 任务会退还其积分。IN_PROGRESS 的任务无法删除,请等待最终状态后再删除。
Request
# Delete a task
curl -X DELETE https://api.meshy.ai/openapi/v2/tasks/018a210d-8ba4-705c-b111-1f1776f7f578 \
-H "Authorization: Bearer ${MESHY_API_KEY}"
409 Conflict
{
"type": "conflict",
"code": "task_in_progress",
"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.",
"doc_url": null
}
参数
- Name
- id
- Type
- path
- 必选
- Description
要删除的任务的 ID。
返回值
200,响应体为空。
Errors
- Name
400 - Bad Request- Description
该 ID 不是有效的任务 ID(
request_invalid)。请发送创建响应中的id。
- Name
404 - Not Found- Description
没有任务的该 ID 属于您的账户,或该任务已被删除(
task_not_found)。Creative Lab 任务也会返回
404。请检查 ID,并使用创建该任务的账户的 API key。
- Name
409 - Conflict- Description
该任务处于
IN_PROGRESS状态。一旦工作进程开始处理,其积分将不可退还。请等待状态变为SUCCEEDED或FAILED后再删除。