快速開始

首先建立你的 API key

本指南中的每個請求都需要用到它。建立金鑰只需幾秒鐘。

建立你的 API key

使用 Meshy REST API,只需四個步驟即可取得你的第一個 3D 模型。


1取得你的 API key

在 開發者平台 的 API Keys 頁面 建立一個 API key —— 離開此頁面後你將無法再次查看它,請妥善保存。每個請求都透過 Authorization 請求標頭中的 Bearer 權杖進行身份驗證 —— 詳見 Authentication。

在開發者平台中開啟 API Keys 頁面,然後建立你的金鑰


2發出你的第一個 Image-to-3D 請求

匯出你的金鑰,然後使用 Image to 3D 建立你的第一個任務。想從文字 prompt 或多張照片入手?請參閱 Text to 3D 或 Multi-Image to 3D。

Export your key

export MESHY_API_KEY="<your-api-key>"

下面的每個範例都使用這張照片 —— 換上你自己的 image_url 即可嘗試其他內容。

Sample fantasy character illustration used as the Image to 3D input in this guide
範例輸入

Request

POST
/openapi/v1/image-to-3d
curl https://api.meshy.ai/openapi/v1/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"
  }'

3檢查任務狀態

請求會立即回傳一個任務 ID。輪詢同一個端點,直到 status 變為 SUCCEEDED —— 將下面的 <task_id> 替換為第 2 步中回傳的 ID。

Request

GET
/openapi/v1/image-to-3d/:id
curl https://api.meshy.ai/openapi/v1/image-to-3d/<task_id> \
  -H "Authorization: Bearer ${MESHY_API_KEY}"

Response — SUCCEEDED

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "status": "SUCCEEDED",
  "progress": 100,
  "model_urls": {
    "glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
    "fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***"
  },
  "thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
  "task_error": {
    "message": ""
  }
}

4下載你的模型

從上面回應中的 model_urls 取得模型。每種格式(GLB、FBX、OBJ、USDZ、STL)都是一個帶簽章的、限時有效的 URL —— 你也可以跳過命令列,直接將 URL 貼到瀏覽器網址列中進行下載。

Download

model_urls.glb
curl -L "<model_urls.glb from the response above>" -o model.glb
The resulting 3D model generated from the sample fantasy character photo
你的結果

整合到一起

想用一個指令碼完成全部流程 —— 建立、輪詢、下載?

Full script

import axios from 'axios';
import fs from 'fs';

const headers = { Authorization: `Bearer ${process.env.MESHY_API_KEY}` };
const imageUrl = 'https://docs.meshy.ai/images/api/quick-start/source-photo.webp';

// 1. Create the task
const { data: created } = await axios.post(
  'https://api.meshy.ai/openapi/v1/image-to-3d',
  { image_url: imageUrl },
  { headers },
);
const taskId = created.result;

// 2. Poll until it finishes
let task;
while (true) {
  const { data } = await axios.get(`https://api.meshy.ai/openapi/v1/image-to-3d/${taskId}`, { headers });
  task = data;
  if (task.status === 'SUCCEEDED' || task.status === 'FAILED') break;
  await new Promise((resolve) => setTimeout(resolve, 5000));
}

// 3. Download the result (only if the task succeeded)
if (task.status !== 'SUCCEEDED') {
  throw new Error(`Task ${task.status}: ${task.task_error?.message || 'unknown error'}`);
}
const { data: model } = await axios.get(task.model_urls.glb, { responseType: 'arraybuffer' });
fs.writeFileSync('model.glb', model);
console.log('Saved model.glb');

探索常見工作流程


後續步驟

  • 更喜歡使用 UI?打開 開發者平台 —— 在 Playground 中執行請求、追蹤用量和請求日誌,並管理 webhooks。
  • 瀏覽完整的 API 參考,了解每個端點。
  • 在投入生產環境之前,請查看 Pricing、速率限制 和 錯誤。
  • 關注 更新日誌,了解更新和錯誤修正。
  • 有意見回饋或遇到問題?加入我們的 Discord 社群 —— 我們很樂意聽取你的意見!