lowpoly 将于 2026年10月30日 下线。 meshy-7 作为 3D 生成模型将于 2026年12月31日 下线;作为贴图模型仍可使用。 请在这些日期前切换模型,以免请求报错。 查看所有弃用信息

快速开始

先创建你的 API key

本指南中的每个请求都需要用到它。创建一个 key 只需几秒钟。

创建你的 API key

通过四个步骤,使用 Meshy API v2 制作你的第一个 3D 模型。你需要获取一个 API key、创建一个任务、在 Tasks 路由上跟踪它,然后下载结果。


1获取您的 API key

在开发者平台的 API Keys 页面上创建一个 API key。离开该页面后您将无法再次查看该密钥,因此请将其妥善保存。请在每个请求中以 Authorization 标头中的 Bearer 令牌形式发送该密钥。请参阅Authentication。

您需要付费套餐才能创建和管理 API key。在免费套餐中,您无法创建自己的密钥,Playground 会使用内置密钥进行测试。

在开发者平台中打开 API Keys 页面,然后创建您的密钥

请将密钥存储在环境变量中,而不是直接粘贴到代码里。请在终端中运行以下命令:

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。

Sample fantasy character illustration used as the Image to 3D input in this guide
Sample input

Request

POST
/openapi/v2/image-to-3d
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

GET
/openapi/v2/tasks/:id
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

output.model_urls.glb
curl -L "<output.model_urls.glb from the response above>" -o model.glb
The resulting 3D model generated from the sample fantasy character photo
Your result

整合所有代码

这段脚本会创建任务、等待任务完成,然后下载模型。

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");

探索常见工作流程


下一步