浮雕 API
将一张照片转换为浅浮雕 3D 模型和 16 位深度图,适用于 3D 打印、激光雕刻和 CNC 雕刻。
创建浮雕任务
创建一个浮雕任务。该任务会将一张照片转换为浮雕模型。任务成功后,会生成 target_formats 中指定格式的模型、一张 16 位灰度深度图,以及一张预览图。如果只想得到深度图,请将 should_generate_model 设为 false。
该任务会在后台运行。
浮雕任务不能作为其他 endpoint(如 Remesh、Convert 或 Auto Split)的输入。此类请求会返回 403。
Request
# Simple request: a low relief, 60 mm on its longer side
curl https://api.meshy.ai/openapi/v1/relief \
-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>"
}'
# Advanced request: a deep, curved, colored 120 mm relief as GLB, OBJ, and STL files
curl https://api.meshy.ai/openapi/v1/relief \
-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>",
"variant": "high",
"size_mm": 120,
"carving_depth_mm": 10,
"base_thickness_mm": 3,
"bend_mode": "convex",
"bend_angle": 90,
"color_mapping": true,
"target_formats": ["glb", "obj", "stl"]
}'
Response
{
"result": "0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20"
}
参数
- Name
- image_url
- Type
- string
- 必选
- Description
要转换为浮雕的照片,可以是公开可访问的 URL,也可以是 Data URI(
data:image/png;base64,...)。图片必须是 JPG、JPEG、PNG 或 WebP 文件,最大不超过 20 MB,尺寸至少为 32 × 32 像素。较长边最多约为较短边的 16 倍。其他图片都会返回
400。Meshy 会在构建浮雕之前将透明区域填充为黑色。
- Name
- variant
- Type
- string
- 默认值 low
- Description
浮雕风格。它决定深度图的形态,并设置
carving_depth_mm的默认值。可用取值:
high:雕刻更深,适合 3D 打印件。low:雕刻较浅,适合激光雕刻、CNC 雕刻和薄牌匾。
传入
null或""等同于不传该 参数。其他任何值都会返回400。
- Name
- should_generate_model
- Type
- boolean
- 默认值 true
- Description
是否构建浮雕模型。设为
false可创建仅生成深度图的任务,不会生成模型和预览图。Meshy 仍会检查尺寸、雕刻、底座、弯曲、分辨率、格式和颜色相关 参数,但不会使用它们。这不会改变积分费用。
- Name
- size_mm
- Type
- number
- 默认值 60
- Description
照片较长边在模型上的长度(在任何弯曲之前的平放状态下测量),范围从
20到250毫米。启用remove_base时,模型可以更小。
- Name
- carving_mode
- Type
- string
- 默认值 emboss
- Description
主体是从底板上凸起还是被切入其中。
可用取值:
emboss:照片中较近的部分会凸起。engrave:深度被反转,因此较近的部分会被切入。
两种模式下深度图相同。
- Name
- carving_depth_mm
- Type
- number
- 默认值 6 (high), 3 (low)
- Description
浮雕的雕刻深度,范围从
0到60毫米。当remove_base设为true时,0会生成一个空模型。该任务仍会成功并耗费 20 积分,其模型文件不包含任何 geometry。
- Name
- remove_base
- Type
- boolean
- 默认值 false
- Description
是否切除背景并且不生成底板。设为
true时,removal_threshold决定哪些部分算作背景。无论该值如何,Meshy 都会校验removal_threshold。
remove_base = true- Name
- removal_threshold
- Type
- number
- 默认值 0.01
- Description
Meshy 据此切除背景的深度阈值,范围从
0.01到1,深度图的取值范围为0到1。设置过高的值可能会切除整个浮雕,留下一个空模型,该任务仍会成功并计费。
- Name
- base_thickness_mm
- Type
- number
- 默认值 1, or 0 with remove_base
- Description
底板厚度,范围从
0.1到10毫米。当remove_base为true时,请省略该 参数或传入0。
- Name
- bend_mode
- Type
- string
- 默认值 off
- Description
是否弯曲浮雕,以及朝哪个方向弯曲。当该值不为
off时,bend_axis和bend_angle决定弯曲的形态。无论取值如何,Meshy 都会校验这两项 参数。可用取值:
off:平整的浮雕。convex:正面向外凸起。concave:正面向内凹陷。
bend_mode = convex or concave- Name
- bend_axis
- Type
- string
- 默认值 xz
- Description
弯曲会卷起哪一对边。
可用取值:
xz:左右两边。yz:上下两边。
- Name
- bend_angle
- Type
- number
- 默认值 60
- Description
弯曲所跨的弧度,范围从
0到360度。低于1时,浮雕仍保持平整。
- Name
- mesh_resolution
- Type
- integer
- 默认值 1024
- Description
沿照片较长边的 mesh 点数,范围从
512到2048。该值越高,细节保留越精细,但文件也会更大。默认值1024下,GLB 文件约为 40 到 50 MB,STL 文件约为 80 到 105 MB。方形照片会生成偏大的文件。在2048时,两者分别约为 150 MB 和 300 MB。弯曲会使文件更大:STL 文件在2048时最大可达约 800 MB。
- Name
- target_formats
- Type
- string[]
- 默认值 ["glb", "stl"]
- Description
要生成的文件格式。Meshy 只会生成并返回你所列出的格式,这可以缩短任务时间。
可用取值:
glbobjfbxstlusdz3mf
STL 和 3MF 文件保留浮雕的真实尺寸。
- Name
- color_mapping
- Type
- boolean
- 默认值 false
- Description
是否用照片为模型上色。GLB、OBJ、FBX 和 USDZ 文件会带有颜色。STL 和 3MF 文件保持白色。任务会在
texture_urls中返回 texture。这不会改变积分费用。
返回值
202 Accepted,其中 result 包含新建浮雕任务的 ID。
失败情形
- Name
400 - Bad Request- Description
请求无法执行。错误信息会说明发现的具体问题。例如:
- 缺少 参数:未传入
image_url。 - 参数无效:某个 参数类型错误、超出范围,或不属于其可用取值之一。例如,
variant不是high或low,mesh_resolution不是512到2048之间的整数,或target_formats中列出了未知格式。 - 底板厚度:
remove_base设为true时base_thickness_mm不为0,或在未设置时该值小于0.1。 - URL 无法访问:Meshy 无法下载
image_url指向的图片,例如该 URL 返回404或超时。 - 图片无效:图片不是 JPG、JPEG、PNG 或 WebP 文件,超过 20 MB,小于 32 × 32 像素,像素过多,或无法读取。
- 宽高比极端:图片较长边超过较短边约 16 倍。
请修正请求后重新发送。Meshy 不会就此计费。参见Errors。
- 缺少 参数:未传入
- Name
401 - Unauthorized- Description
API key 缺失或无效。请检查
Authorization请求头。
- Name
402 - Payment Required- Description
例如:
- 积分不足:账户没有足够的积分来执行该任务,或账户已达到积分限额。请检查你的账户 balance,然后重试。
- 免费方案:创建任务需要付费方案。请在subscription 设置中升级你的方案,然后重试。
- Name
403 - Forbidden- Description
内容审核拦截了该图片。Meshy 不会就此请求计费。请发送另一张图片。
- Name
429 - Too Many Requests- Description
达到以下某个限制:
- 你发送的请求过多。请稍候后重试。参见速率限制。
- 你排队或正在运行的任务过多。请等待部分任务完成后重试。
- 在无限制方案下积分已用尽,你已达到无需积分即可运行的任务数量上限。请等待某个任务完成,或增加积分。
如果安全检查在任务运行期间拒绝了该图片,任务会失败,task_error.type 会被设为 invalid_input,task_error.code 会被设为 provider_content_refused。Meshy 会退还该任务的积分。请发送另一张图片。参见Errors。
获取 Relief 任务
根据 ID 返回一个 Relief 任务。
Request
curl https://api.meshy.ai/openapi/v1/relief/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
{
"id": "0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20",
"type": "relief",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.glb?Expires=***",
"stl": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.stl?Expires=***"
},
"depth_map_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/depth.png?Expires=***",
"thumbnail_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/preview.png?Expires=***",
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000060000,
"expires_at": 1700259260000,
"task_error": null,
"consumed_credits": 20
}
删除浮雕任务
永久删除一个浮雕任务,包括其模型、深度图和数据。删除后无法撤销。
Request
curl --request DELETE \
--url https://api.meshy.ai/openapi/v1/relief/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20 \
-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 keeps 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."
}
路径参数
- Name
- id
- Type
- path
- Description
要删除的任务的 ID。
任务状态
删除一个 PENDING 任务会退还创建该任务时所用的积分。
IN_PROGRESS 任务无法删除。该请求会返回 409 Conflict,
任务会继续运行。Meshy 不会为已经开始的任务退款,
因此删除它会让你同时损失积分和结果。请等待任务
变为 SUCCEEDED 或 FAILED 状态后再删除。
删除一个 SUCCEEDED 任务不会退还其积分。FAILED 任务在失败时已经退过款了。
返回值
任务删除成功时返回 200 OK;当任务处于
IN_PROGRESS 状态时返回 409 Conflict。
获取浮雕任务列表
返回你的浮雕任务列表。
Request
curl https://api.meshy.ai/openapi/v1/relief?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
[
{
"id": "0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20",
"type": "relief",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.glb?Expires=***",
"stl": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.stl?Expires=***"
},
"depth_map_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/depth.png?Expires=***",
"thumbnail_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/preview.png?Expires=***",
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000060000,
"expires_at": 1700259260000,
"task_error": null,
"consumed_credits": 20
}
]
参数
- Name
- page_num
- Type
- integer
- Description
要返回的页码。起始值和默认值均为
1。
- Name
- page_size
- Type
- integer
- Description
每页返回的任务数量,最多为
100。默认值为10。Meshy 会将101到255之间的值视为100,更大的值会返回400。
- Name
- sort_by
- Type
- string
- Description
排序方式。
可用值:
+created_at:最早优先-created_at:最新优先
返回值
分页的浮雕任务对象列表。
流式获取浮雕任务
以服务器发送事件(SSE)的形式流式传输浮雕任务的更新。
Request
curl -N https://api.meshy.ai/openapi/v1/relief/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response Stream
// Error event example
event: error
data: {
"status_code": 404,
"message": "Task not found"
}
// Message event examples illustrate task progress (other task fields omitted here for brevity;
// each frame is the full task object).
event: message
data: {
"id": "0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20",
"progress": 0,
"status": "PENDING"
}
event: message
data: {
"id": "0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20",
"type": "relief",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.glb?Expires=***",
"stl": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.stl?Expires=***"
},
"depth_map_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/depth.png?Expires=***",
"thumbnail_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/preview.png?Expires=***",
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000060000,
"expires_at": 1700259260000,
"task_error": null,
"consumed_credits": 20
}
参数
- Name
- id
- Type
- path
- Description
创建响应中返回的任务 ID。
返回
以服务器发送事件的形式返回 浮雕任务对象 的流。
每个 message 事件都携带完整的任务对象,与 获取浮雕任务 返回的对象相同。当任务处于 PENDING 或 IN_PROGRESS 状态时,事件之间会变化的字段是 progress、status、started_at 和 preceding_tasks(仅在该任务前面还有排队任务时才会出现)。当任务到达 SUCCEEDED 状态时,model_urls、texture_urls、depth_map_url 和 thumbnail_url 才会被赋值。仅生成深度图的任务会保持 model_urls 为 {},thumbnail_url 为空。
error 事件只包含 status_code 和 message,因此在读取 status 之前请先检查事件名称。
浮雕任务对象
浮雕任务对象描述一个由照片生成的浮雕。model_urls、depth_map_url 和 thumbnail_url 始终存在,在任务成功之前为空。
The Relief Task Object
{
"id": "0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20",
"type": "relief",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.glb?Expires=***",
"stl": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/model.stl?Expires=***"
},
"depth_map_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/depth.png?Expires=***",
"thumbnail_url": "https://assets.meshy.ai/***/tasks/0199c3d2-5a7e-7b14-9e2f-3c8d1a6b4f20/output/preview.png?Expires=***",
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000060000,
"expires_at": 1700259260000,
"task_error": null,
"consumed_credits": 20
}
Depth map only
{
"id": "0199c3d2-6b8f-7c25-8f3a-4d9e2b7c5a31",
"type": "relief",
"model_urls": {},
"depth_map_url": "https://assets.meshy.ai/***/tasks/0199c3d2-6b8f-7c25-8f3a-4d9e2b7c5a31/output/depth.png?Expires=***",
"thumbnail_url": "",
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000030000,
"expires_at": 1700259230000,
"task_error": null,
"consumed_credits": 20
}
Colored model
{
"id": "0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42",
"type": "relief",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42/output/model.glb?Expires=***",
"stl": "https://assets.meshy.ai/***/tasks/0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42/output/model.stl?Expires=***",
"obj": "https://assets.meshy.ai/***/tasks/0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42/output/model.obj?Expires=***",
"mtl": "https://assets.meshy.ai/***/tasks/0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42/output/model.mtl?Expires=***"
},
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42/output/texture_0.png?Expires=***"
}
],
"depth_map_url": "https://assets.meshy.ai/***/tasks/0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42/output/depth.png?Expires=***",
"thumbnail_url": "https://assets.meshy.ai/***/tasks/0199c3d2-7c90-7d36-9a4b-5e0f3c8d6b42/output/preview.png?Expires=***",
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1699999999000,
"started_at": 1700000000000,
"finished_at": 1700000060000,
"expires_at": 1700259260000,
"task_error": null,
"consumed_credits": 20
}
- Name
- id
- Type
- string
- Description
任务 ID。将其视为不透明字符串,不要依赖其格式。
- Name
- type
- Type
- string
- Description
任务类型,始终为
relief。
- Name
- model_urls
- Type
- object
- Description
浮雕模型的下载链接,
target_formats中每种格式对应一个。仅生成深度图的任务没有此字段。文件可能较大;mesh_resolution列出了典型大小。- Name
glb- Type
- string
- Description
GLB 文件。单位为米。仅当
color_mapping: true时才带有 texture。
- Name
obj- Type
- string
- Description
OBJ 文件。仅当
color_mapping: true时才带有 texture。
- Name
mtl- Type
- string
- Description
MTL 文件,与 OBJ 文件一起返回。
- Name
fbx- Type
- string
- Description
FBX 文件。仅当
color_mapping: true时才带有 texture。
- Name
stl- Type
- string
- Description
二进制 STL 文件。单位为毫米,因此打开后即为浮雕的真实大小,Z 轴朝上。
- Name
usdz- Type
- string
- Description
USDZ 文件。仅当
color_mapping: true时才带有 texture。
- Name
3mf- Type
- string
- Description
3MF 文件。
- Name
- texture_urls
- Type
- array
- Description
彩色模型的 texture,是一个仅含一个对象的数组。仅当你在创建任务时设置
color_mapping: true才会出现。- Name
base_color- Type
- string
- Description
基础颜色贴图的下载链接。
- Name
- depth_map_url
- Type
- string
- Description
浮雕所依据的 16 位灰度深度图的下载链接。像素越亮表示越高。这些值是相对高度,而非毫米数。激光雕刻和 CNC 软件可以将其用作高度图。文件大小约为 1 到 2 MB。若不存在则为空。
- Name
- thumbnail_url
- Type
- string
- Description
浮雕模型预览图的下载链接。若未渲染预览图(包括仅生成深度图的任务),则为空。
- Name
- progress
- Type
- integer
- Description
任务完成的百分比。任务开始前为
0,任务成功后为100。
- Name
- status
- Type
- string
- Description
任务状态,取值为
PENDING、IN_PROGRESS、SUCCEEDED或FAILED之一。
- Name
- preceding_tasks
- Type
- integer
- Description
排在此任务之前的任务数量。当该值为
0时该字段会被省略,因此只有在有任务排在此任务之前时才会出现。
- Name
- created_at
- Type
- timestamp
- Description
任务创建的时间,以 Unix 毫秒表示。
- Name
- started_at
- Type
- timestamp
- Description
任务开始的时间,以 Unix 毫秒表示。任务开始前为
0。
- Name
- finished_at
- Type
- timestamp
- Description
任务完成的时间,以 Unix 毫秒表示。任务完成前为
0。
- Name
- expires_at
- Type
- timestamp
- Description
任务结果过期的时间,以 Unix 毫秒表示。任务完成前为
0。
- Name
- task_error
- Type
- object
- Description
任务失败时的错误详情。参见 Errors。
- Name
- consumed_credits
- Type
- integer
- Description
任务消耗的积分数:
20,或对于FAILED的任务为0,Meshy 会退还该积分。