Creative Lab 方块小人 API
通过两个阶段,将一张照片转换为方块风格的收藏款 3D 小人(minifigure)。原型任务会根据照片生成一张概念图,构建任务则将该图像转换为带纹理的 3D 模型,并以原型任务的 ID 作为 input_task_id。
POST /openapi/creative-lab/brick-figure/v1/prototypePOST /openapi/creative-lab/brick-figure/v1/build
创建 Brick Figure prototype 任务
根据一张照片生成一张方块风格的概念图。要构建 3D 模型,请将此任务的 ID 作为 input_task_id 传递给 build endpoint。有关任务字段的说明,请参阅 The Brick Figure prototype task object。
Request
# Stage 1: generate a brick-style concept image
curl https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/prototype \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"image_url": "<your publicly accessible image url or base64-encoded data URI>"
}'
Response
{
"result": "018a210d-8ba4-705c-b111-1f1776f7f578"
}
参数
- Name
- image_url
- Type
- string
- 必选
- Description
要转换为方块小人的照片,可以是公开可访问的 URL 或 data URI(
data:image/jpeg;base64,<your base64-encoded image data>)。图片必须是 JPG、JPEG、PNG 或 WebP 文件,且大小不超过 20 MB。
- Name
- name
- Type
- string
- Description
任务的名称,最多 100 个字符。它会在任务的
name字段中返回。名称过长会返回400。
- Name
- remove_background
- Type
- boolean
- 默认值 false
- Description
是否从原型图片中移除背景。
true会返回一张透明的 RGBA PNG,这样你就可以将主体放到任意背景上。构建过程也会使用去除背景后的图片作为起点。如果 Meshy 无法移除背景,它会返回带有原始背景的图片,任务仍然会成功。
返回值
result 字段保存新建的 prototype 任务的 ID。获取该任务或对其进行流式获取,直到 status 变为 SUCCEEDED。然后将该 ID 作为 input_task_id 传递给 build endpoint。
失败模式
- Name
400 - Bad Request- Description
请求无法执行。例如:
- 缺少
image_url。 - 图片不是 JPG、JPEG、PNG 或 WebP 文件。
- 图片过小、超过 20 MB,或超过了最大像素数。
- Meshy 无法下载该图片,例如因为该 URL 返回了
404或超时。 - data URI 不是有效的 base64 编码。
- 该图片被标记为 NSFW。
错误信息会说明具体发现了哪个问题。修正请求后重新发送。
- 缺少
- Name
401 - Unauthorized- Description
API key 缺失或无效。请检查
Authorization请求头。
- Name
402 - Payment Required- Description
以下情况之一适用:
- 账户没有足够的积分。
- API key、workspace 或成员已达到其积分限额。
- 账户使用的是免费套餐。
请检查你的积分和套餐,然后重试。
- Name
403 - Forbidden- Description
你的团队已开启 IP Filtering,Meshy 将该图片标记为涉及第三方知识产权。请发送你拥有使用权利的图片。
- Name
429 - Too Many Requests- Description
达到了以下某个限制:
- 你发送的请求数超出了速率限制。请等待几秒钟后重试。参见 Rate limits。
- 你排队或正在运行的任务过多。请等待部分任务完成后重试。
- 在没有积分的无限套餐下,已达到可在无积分情况下运行的任务数量上限。请等待某个任务完成,或增加积分。
- Name
500 - Internal Server Error- Description
Meshy 遇到了服务器错误,例如无法对图片执行知识产权检查。Meshy 不会创建该任务,并会退还已收取的任何积分。请重试该请求。
创建方块小人构建任务
根据一个已成功的原型任务生成带贴图的 3D 小人模型。有关其字段信息,请参阅 The Brick Figure build task object。
Request
# Stage 2: chain build off a succeeded prototype task
curl https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/build \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578"
}'
Response
{
"result": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb"
}
参数
- Name
- input_task_id
- Type
- string
- 必选
- Description
要构建的原型任务的 ID。它必须是你的账户通过
POST /openapi/creative-lab/brick-figure/v1/prototype创建的任务,且状态为SUCCEEDED。如果该 ID 不是你通过 API 创建的 Brick Figure 原型任务之一,将返回
404,这也包括在 web app 中创建的原型。
- Name
- name
- Type
- string
- Description
任务的名称,最多 100 个字符。它会在任务的
name字段中返回。名称过长会返回400。
返回值
result 字段保存新构建任务的 ID。获取任务或流式获取任务,直到 status 变为 SUCCEEDED。然后从 model_urls.glb 下载带贴图的 GLB。如果需要 OBJ,则从 model_urls.obj 下载 OBJ,并从 model_urls.mtl 下载其 material 文件。
失败模式
- Name
400 - Bad Request- Description
请求无法执行。例如:
input_task_id缺失或不是有效的任务 ID。- 原型任务的状态不是
SUCCEEDED。如果仍在运行,请等待后重试。如果已失败或被取消,请创建一个新的原型任务。 - 原型任务已成功,但没有图片。请创建一个新的原型任务。
错误消息会说明具体发现了哪个问题。
- Name
401 - Unauthorized- Description
API key 缺失或无效。请检查
Authorization请求头。
- Name
402 - Payment Required- Description
以下情况之一适用:
- 账户的积分不足。
- API key、workspace 或成员已达到其积分限额。
- 账户处于免费套餐。
请检查你的积分和套餐,然后重试。
- Name
404 - Not Found- Description
input_task_id与你的账户通过 API 创建的任何 Brick Figure 原型任务都不匹配。在 web app 中创建的原型也会返回404。请发送来自原型创建响应的resultID。
- Name
429 - Too Many Requests- Description
达到了以下限制之一:
- 你发送的请求数超过了速率限制所允许的数量。请等待几秒钟后重试。参阅 Rate limits。
- 你排队或正在运行的任务太多。请等待部分任务完成后重试。
- 在不限量套餐下且没有剩余积分时,你达到了无需积分即可运行的任务数量上限。请等待某个任务完成,或添加积分。
获取方块小人任务
返回一个 prototype 或 build 任务。路径必须与任务所处的阶段相匹配。通过 /prototype/:id 请求的 build 任务会返回 404,通过 /build/:id 请求的 prototype 任务同样会返回 404。
有关字段说明,请参阅 Brick Figure prototype 任务对象 和 Brick Figure build 任务对象。
Request
# Prototype
curl https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/prototype/018a210d-8ba4-705c-b111-1f1776f7f578 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
# Build
curl https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/build/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Prototype Response
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "creative-lab-brick-figure-prototype",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123456000,
"started_at": 1729123460000,
"finished_at": 1729123486000,
"expires_at": 1729382686000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 6,
"image_urls": [
"https://assets.meshy.ai/***/concept.png?Expires=***"
]
}
Build Response
{
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"type": "creative-lab-brick-figure-build",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123500000,
"started_at": 1729123510000,
"finished_at": 1729123535000,
"expires_at": 1729382735000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 30,
"prompt": "",
"negative_prompt": "",
"texture_prompt": "",
"texture_image_url": "",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.glb?Expires=***",
"obj": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.obj?Expires=***",
"mtl": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.mtl?Expires=***"
},
"thumbnail_url": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/preview.png?Expires=***",
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/texture_0.png?Expires=***"
}
]
}
参数
- Name
- id
- Type
- path
- Description
创建响应中返回的任务 ID。
返回值
与路径中阶段相匹配的 prototype 任务对象 或 build 任务对象。
失败模式
- Name
400 - Bad Request- Description
id不是有效的任务 ID。请发送创建响应中的resultID。
- Name
403 - Forbidden- Description
你的团队开启了 IP Filtering(IP 过滤)功能,Meshy 判定该任务的图片涉及第三方知识产权。Enterprise 计划的团队不会收到此错误。请使用你拥有使用权的图片创建 prototype 任务。
- Name
404 - Not Found- Description
你的账户下没有此 ID 对应的 Brick Figure 任务,或者该任务所处的阶段与路径不匹配。请检查 ID,并使用
/prototype或/build与任务进行匹配。
- Name
500 - Internal Server Error- Description
Meshy 无法执行知识产权检查。请重试该请求。
删除 Brick Figure 任务
取消一个 Brick Figure 任务。取消一个 PENDING 任务会退还其积分。IN_PROGRESS 任务被取消时不会退款,因为已有工作进程开始处理该任务。处于最终状态(SUCCEEDED、FAILED 或 CANCELED)的任务无法被取消。
路径必须与任务所处的阶段匹配。例如,使用构建任务的 ID 对 /prototype/:id 执行 DELETE 操作会返回 404。
Request
curl --request DELETE \
--url https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/prototype/018a210d-8ba4-705c-b111-1f1776f7f578 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
// Returns 204 No Content on success (empty body).
路径参数
- Name
- id
- Type
- path
- Description
要取消的任务的 ID。
返回值
204 No Content,响应体为空。
失败模式
- Name
400 - Bad Request- Description
以下情况之一:
id不是有效的任务 ID。请发送创建响应中的resultID。- 任务已处于最终状态(
SUCCEEDED、FAILED或CANCELED),因此无法取消。
- Name
404 - Not Found- Description
你的账户下没有该 ID 对应的 Brick Figure 任务,或者该任务所处的阶段与路径不匹配。请检查 ID,并使用
/prototype或/build来匹配该任务。
流式获取 Brick Figure 任务
以服务器发送事件(SSE)的形式流式获取 Brick Figure 任务的更新。路径必须与任务所处的阶段相匹配。如果不匹配,例如将 build 任务的 ID 用于 /prototype/:id/stream,该流会发送一条 status_code: 404 的 error 事件,然后关闭。
Request
curl -N https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/build/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response Stream
// Error event example (wrong stage or task not found)
event: error
data: {
"status_code": 404,
"message": "Task not found"
}
// Message event examples illustrate task progress.
// Every frame is the full task object; fields not yet populated are null / empty.
// The following PENDING frame is shortened to the fields that change.
event: message
data: {
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"progress": 0,
"status": "PENDING"
}
event: message
data: {
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"type": "creative-lab-brick-figure-build",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123500000,
"started_at": 1729123510000,
"finished_at": 1729123535000,
"expires_at": 1729382735000,
"task_error": null,
"consumed_credits": 30,
"prompt": "",
"negative_prompt": "",
"texture_prompt": "",
"texture_image_url": "",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.glb?Expires=***",
"obj": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.obj?Expires=***",
"mtl": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.mtl?Expires=***"
},
"thumbnail_url": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/preview.png?Expires=***",
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/texture_0.png?Expires=***"
}
]
}
参数
- Name
- id
- Type
- path
- Description
创建响应中返回的任务 ID。
返回
一个由 prototype 或 build 任务对象组成的流。每个事件都包含完整的任务对象,与 获取 Brick Figure 任务 返回的内容一致。当任务处于 PENDING 或 IN_PROGRESS 状态时,其输出字段仍为空(null、[] 或 {}),且 finished_at 为 null。
如果IP 过滤功能阻止了任务结果的返回,该流会在相应位置发送一条 error 事件,其中 status_code 与 get 请求本应返回的值一致。
获取 Brick Figure 任务列表
返回你某一阶段的 Brick Figure 任务,每次返回一页。路径决定阶段:/prototype 仅返回 prototype 任务,/build 仅返回 build 任务。
Request
# List prototype tasks
curl https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/prototype?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
# List build tasks
curl https://api.meshy.ai/openapi/creative-lab/brick-figure/v1/build?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response (List Prototype Tasks)
[
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "creative-lab-brick-figure-prototype",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123456000,
"started_at": 1729123460000,
"finished_at": 1729123486000,
"expires_at": 1729382686000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 6,
"image_urls": [
"https://assets.meshy.ai/***/concept.png?Expires=***"
]
}
]
路径参数
- Name
- stage
- Type
- path
- 必选
- Description
要获取的阶段,
prototype或build。
查询参数
- 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:最旧的排在最前
返回值
一个由prototype 任务对象或build 任务对象组成的数组,具体取决于路径中指定的阶段。
Brick Figure prototype 任务对象
prototype 任务会根据照片生成方块风格的概念图像。要将图像转换为 3D 模型,请将该任务的 ID 作为 input_task_id 传给build endpoint。
Properties
Example Brick Figure Prototype Task Object
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "creative-lab-brick-figure-prototype",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123456000,
"started_at": 1729123460000,
"finished_at": 1729123486000,
"expires_at": 1729382686000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 6,
"image_urls": [
"https://assets.meshy.ai/***/concept.png?Expires=***"
]
}
- Name
- id
- Type
- string
- Description
任务 ID。不要依赖其格式。
- Name
- type
- Type
- string
- Description
任务类型,始终为
creative-lab-brick-figure-prototype。
- Name
- name
- Type
- string
- Description
创建任务时你发送的
name,如果没有发送则为""。
- Name
- status
- Type
- string
- Description
任务的状态。
可用值:
PENDING:在队列中等待IN_PROGRESS:正在生成结果SUCCEEDED:最终状态,附带结果FAILED:最终状态,原因见task_errorCANCELED:最终状态,没有结果
- Name
- progress
- Type
- integer
- Description
已完成工作的百分比,范围从
0到100。任务开始前为0,成功后为100。
- Name
- created_at
- Type
- timestamp
- Description
任务创建的时间,以 Unix 毫秒表示。
- Name
- started_at
- Type
- timestamp
- Description
工作进程开始执行任务的时间,以 Unix 毫秒表示。在此之前为
null。
- Name
- finished_at
- Type
- timestamp
- Description
任务达到最终状态的时间,以 Unix 毫秒表示。在此之前为
null。
- Name
- expires_at
- Type
- timestamp
- Description
任务结果过期的时间,以 Unix 毫秒表示。该时间为
finished_at之后 3 天;在任务完成之前,则为created_at之后 3 天。对于会无限期保留 API 结果的企业版账户,该时间约为 100 年后。请参阅资产保留期。
- Name
- preceding_tasks
- Type
- integer
- Description
任务处于
PENDING状态时在队列中的位置。1表示接下来就会开始执行。任务离开队列后为0,在列表结果中始终为0。
- Name
- task_error
- Type
- object
- Description
任务失败的原因。除非
status为FAILED,否则为null。请参阅Errors。
- Name
- consumed_credits
- Type
- integer
- Description
任务扣除的积分数量(已扣除任何退款部分)。返回错误的请求不会被扣费。失败的任务为
0,因为 Meshy 会对其进行退款。取消任务仅在其处于PENDING状态时才会退款。如果 Meshy 无法读取扣费信息,get 或 stream 响应会省略该字段,而 list 请求会返回500。在这种情况下,请重试该请求。
- Name
- image_urls
- Type
- array of strings
- Description
概念图像的下载 URL。任务成功后,该数组中会有一个 URL;在此之前为空数组。
Brick Figure 构建任务对象
构建任务会根据一个成功的原型任务生成带贴图的 3D 小人模型。其 model_urls、thumbnail_url 和 texture_urls 字段的格式与 Image to 3D 任务对象中的相同。
属性
Example Brick Figure Build Task Object
{
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"type": "creative-lab-brick-figure-build",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123500000,
"started_at": 1729123510000,
"finished_at": 1729123535000,
"expires_at": 1729382735000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 30,
"prompt": "",
"negative_prompt": "",
"texture_prompt": "",
"texture_image_url": "",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.glb?Expires=***",
"obj": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.obj?Expires=***",
"mtl": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.mtl?Expires=***"
},
"thumbnail_url": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/preview.png?Expires=***",
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/texture_0.png?Expires=***"
}
]
}
- Name
- id
- Type
- string
- Description
任务 ID。不要依赖其格式。
- Name
- type
- Type
- string
- Description
任务类型,始终为
creative-lab-brick-figure-build。
- Name
- name
- Type
- string
- Description
创建任务时发送的
name,如果没有发送则为""。
- Name
- status
- Type
- string
- Description
任务的状态。
可用的值:
PENDING:在队列中等待IN_PROGRESS:正在生成结果SUCCEEDED:最终状态,附带结果FAILED:最终状态,原因在task_error中CANCELED:最终状态,无结果
- Name
- progress
- Type
- integer
- Description
已完成工作的百分比,从
0到100。任务开始前为0,成功时为100。
- Name
- created_at
- Type
- timestamp
- Description
任务创建的时间,以 Unix 毫秒表示。
- Name
- started_at
- Type
- timestamp
- Description
工作进程开始处理任务的时间,以 Unix 毫秒表示。在此之前为
null。
- Name
- finished_at
- Type
- timestamp
- Description
任务达到最终状态的时间,以 Unix 毫秒表示。在此之前为
null。
- Name
- expires_at
- Type
- timestamp
- Description
任务结果过期的时间,以 Unix 毫秒表示。该时间为
finished_at之后 3 天,或在任务完成之前为created_at之后 3 天。对于无限期保留 API 结果的企业账户,该时间约为 100 年后。请参阅资产保留期。
- Name
- preceding_tasks
- Type
- integer
- Description
任务处于
PENDING状态时在队列中的位置。1表示下一个开始处理。任务离开队列后为0,在列表结果中始终为0。
- Name
- task_error
- Type
- object
- Description
任务失败的原因。除非
status为FAILED,否则为null。请参阅 Errors。
- Name
- consumed_credits
- Type
- integer
- Description
任务扣除的积分数量,已扣除任何退款。返回错误的请求不会被扣费。失败的任务为
0,因为 Meshy 会退还费用。只有在任务处于PENDING状态时取消才会退款。如果 Meshy 无法读取扣费信息,get 或 stream 响应会省略该字段,而 list 请求会返回500。在这种情况下,请重试该请求。
- Name
- prompt
- Type
- string
- Description
对于 Brick Figure 构建任务,始终为
""。
- Name
- negative_prompt
- Type
- string
- Description
与
prompt一样,对于 Brick Figure 构建任务始终为""。
- Name
- texture_prompt
- Type
- string
- Description
与
prompt一样,对于 Brick Figure 构建任务始终为""。
- Name
- texture_image_url
- Type
- string
- Description
与
prompt一样,对于 Brick Figure 构建任务始终为""。
- Name
- model_urls
- Type
- object
- Description
3D 模型的下载 URL,包括带贴图的 GLB 文件,以及附带 MTL 文件的 OBJ 文件。
- Name
glb- Type
- string
- Description
带贴图的 GLB 文件的下载 URL。
- Name
obj- Type
- string
- Description
OBJ 文件的下载 URL,包含 geometry 和 UV。
- Name
mtl- Type
- string
- Description
与
obj配套使用的 MTL material 文件的下载 URL。请将其与obj以及texture_urls[0].base_color中的 texture 一起使用。
- Name
- thumbnail_url
- Type
- string
- Description
模型预览图片的下载 URL。
- Name
- texture_urls
- Type
- array
- Description
贴图集,是一个数组,其中包含一个存有基础颜色贴图的对象。
- Name
base_color- Type
- string
- Description
基础颜色贴图的下载 URL。