快速开始
先创建你的 API key
本指南中的每个请求都需要用到它。创建一个 key 只需几秒钟。
创建你的 API key通过四个步骤,使用 Meshy API v2 制作你的第一个 3D 模型。你需要获取一个 API key、创建一个任务、在 Tasks 路由上跟踪它,然后下载结果。
从 v1 迁移?请改为参阅 迁移到 API v2。
1获取您的 API key
在开发者平台的 API Keys 页面上创建一个 API key。离开该页面后您将无法再次查看该密钥,因此请将其妥善保存。请在每个请求中以 Authorization 标头中的 Bearer 令牌形式发送该密钥。请参阅Authentication。
您需要付费套餐才能创建和管理 API key。在免费套餐中,您无法创建自己的密钥,Playground 会使用内置密钥进行测试。

请将密钥存储在环境变量中,而不是直接粘贴到代码里。请在终端中运行以下命令:
Export your key
export MESHY_API_KEY="<your-api-key>"
JavaScript 示例使用 fetch,该功能内置于 Node.js 18 及更高版本中。Python 示例使用 requests(pip install requests)。
2创建一个 Image to 3D 任务
将一张图片发送到 Image to 3D。如果想改为从文本提示或多张照片开始,可以使用 Text to 3D 或 Multi-Image to 3D。从这里开始,每个 endpoint 的用法都是一样的。
以下示例均使用这张照片,并使用 texture_model 所选择的 Meshy 7 为模型生成 texture。如需尝试其他图片,请修改 image_url。如需选择其他 texture 模型,请参阅 Texture models。

Request
curl https://api.meshy.ai/openapi/v2/image-to-3d \
-X POST \
-H "Authorization: Bearer ${MESHY_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://docs.meshy.ai/images/api/quick-start/source-photo.webp",
"texture_model": "meshy-7"
}'
响应为 202 Accepted,并返回 task 对象。请保存其中的 id,因为接下来的每一步都需要用到它。Location 响应头给出了读取该任务的路径。
Response: 202 Accepted
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "image-to-3d",
"status": "PENDING",
"progress": 0,
"created_at": 1791846275575,
"started_at": null,
"finished_at": null,
"expires_at": null,
"preceding_tasks": 1,
"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
}
3获取任务直到完成
任务在后台运行,通常需要大约 2 分钟。从 /openapi/v2/tasks/<task_id> 获取任务信息,直到 status 变为 SUCCEEDED、FAILED 或 CANCELED。在两次请求之间,请等待 Retry-After 响应头中指定的秒数。
同一路由适用于来自所有 endpoint 的任务。有关典型处理时间,以及放弃等待之前应等多久,请参阅处理时间和应等待多久。
Request
curl https://api.meshy.ai/openapi/v2/tasks/<task_id> \
-H "Authorization: Bearer ${MESHY_API_KEY}"
Response: SUCCEEDED
{
"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
}
]
}
}
如果任务失败,status 会变为 FAILED,task_error 会说明原因。请修正输入内容或重新创建一个任务。请参阅 Errors。
4下载你的模型
文件位于 output 中。output.model_urls.glb 是一个签名 URL,在 expires_at 之前都有效。你也可以将其粘贴到浏览器中下载文件。
Image to 3D 默认只返回 GLB 文件,除非你在创建任务时在 target_formats 中列出其他格式。
Download
curl -L "<output.model_urls.glb from the response above>" -o model.glb

除企业版(Enterprise)外的所有套餐,Meshy 都会将文件保留 3 天。请在此之前下载所需文件。参见资产保留期。
整合所有代码
这段脚本会创建任务、等待任务完成,然后下载模型。
Full script
import { writeFile } from "node:fs/promises";
const API = "https://api.meshy.ai/openapi/v2";
const headers = {
Authorization: `Bearer ${process.env.MESHY_API_KEY}`,
"Content-Type": "application/json",
};
async function call(path, init = {}) {
const res = await fetch(`${API}${path}`, {
...init,
headers,
signal: AbortSignal.timeout(init.method === "POST" ? 60_000 : 30_000),
});
if (!res.ok) throw new Error(`${res.status}: ${(await res.json()).message}`);
return { body: await res.json(), retryAfter: Number(res.headers.get("retry-after")) || 5 };
}
// 1. Create the task
let { body: task, retryAfter } = await call("/image-to-3d", {
method: "POST",
body: JSON.stringify({
image_url: "https://docs.meshy.ai/images/api/quick-start/source-photo.webp",
texture_model: "meshy-7",
}),
});
// 2. Get the task until it finishes, for up to 60 minutes
const deadline = task.created_at + 60 * 60 * 1000;
while (!["SUCCEEDED", "FAILED", "CANCELED"].includes(task.status)) {
if (Date.now() > deadline) {
// The task is still running. Check it again later with the same ID instead of creating a new one.
throw new Error(`Task ${task.id} is still ${task.status}; check it again later`);
}
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
({ body: task, retryAfter } = await call(`/tasks/${task.id}`));
}
// 3. Download the model (only if the task succeeded)
if (task.status !== "SUCCEEDED") {
throw new Error(`Task ${task.status}: ${task.task_error?.message ?? "unknown error"}`);
}
const file = await fetch(task.output.model_urls.glb);
await writeFile("model.glb", Buffer.from(await file.arrayBuffer()));
console.log("Saved model.glb");
探索常见工作流程
游戏可用角色
为人形模型添加骨骼进行绑定,使其可以在 Unity 或 Unreal 中直接用于动画制作。
Learn more →Smart Topology mesh
在 Image to 3D 中将 ai_model 设置为 meshy-smart-topology-latest,即可获得一个干净、可直接用于游戏的三角形 mesh。
3D 打印模型
将完成的模型转换为多色 3MF 文件,可直接用于切片和打印。
Learn more →下一步
- 了解每个 endpoint 共用的任务对象和 Tasks 路由。
- 在 API v2 概览中浏览所有 endpoint。
- 在上线生产环境前,请查看 Pricing、速率限制和 Errors。
- 更喜欢图形界面?Developer Platform 让你可以在 Playground 中运行请求、跟踪用量和请求日志,并管理 webhooks。
- 在 Cookbook 中跟随循序渐进的实例操作,并在 Developer Blog 上阅读教程。
- 有反馈或遇到问题?加入 Meshy 的 Discord community。