lowpoly จะยุติการให้บริการในวันที่ 30 ต.ค. 2569 meshy-7 ในฐานะโมเดลสร้าง 3D จะยุติการให้บริการในวันที่ 31 ธ.ค. 2569 แต่ยังใช้เป็นโมเดลเท็กซ์เจอร์ได้ตามเดิม โปรดเปลี่ยนโมเดลก่อนวันที่เหล่านี้เพื่อหลีกเลี่ยงข้อผิดพลาดของคำขอ ดูการเลิกใช้งานทั้งหมด

เริ่มต้นอย่างรวดเร็ว

เริ่มต้นด้วยการสร้าง API คีย์ของคุณ

ทุกคำขอในคู่มือนี้ต้องใช้ API คีย์ การสร้างคีย์ใช้เวลาเพียงไม่กี่วินาที

สร้าง API คีย์ของคุณ

สร้างโมเดล 3D ตัวแรกของคุณด้วย Meshy API v2 ในสี่ขั้นตอน คุณจะได้รับ API คีย์ สร้างงาน ติดตามงานผ่านเส้นทาง Tasks และดาวน์โหลดผลลัพธ์


1รับ API คีย์ของคุณ

สร้าง API คีย์ บนหน้า API Keys ของ Developer Platform คุณจะไม่สามารถดูคีย์นี้ได้อีกหลังจากออกจากหน้าจอนั้น ดังนั้นควรเก็บไว้ในที่ปลอดภัย ส่งคีย์นี้ในทุกคำขอในรูปแบบ Bearer token ภายใน Authorization header ดูรายละเอียดที่ Authentication

คุณต้องมีแพ็กเกจแบบชำระเงินเพื่อสร้างและจัดการ API คีย์ สำหรับแพ็กเกจ Free คุณไม่สามารถสร้างคีย์ของคุณเองได้ และ Playground จะใช้คีย์ในตัวสำหรับการทดสอบ

เปิดหน้า API Keys ใน Developer Platform จากนั้นสร้างคีย์ของคุณ

เก็บคีย์ไว้ในตัวแปรสภาพแวดล้อมแทนการวางลงในโค้ดของคุณโดยตรง รันคำสั่งนี้ในเทอร์มินัลของคุณ:

Export your key

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

ตัวอย่าง JavaScript ใช้ fetch ซึ่งมีมาในตัวตั้งแต่ Node.js 18 เป็นต้นไป ส่วนตัวอย่าง Python ใช้ requests (pip install requests)


2สร้างงานรูปภาพเป็น 3D

ส่งรูปภาพไปยัง รูปภาพเป็น 3D หากต้องการเริ่มจาก prompt ข้อความหรือรูปภาพหลายรูปแทน ให้ใช้ ข้อความเป็น 3D หรือ หลายรูปเป็น 3D เอนด์พอยต์ทุกตัวทำงานในลักษณะเดียวกันจากจุดนี้ไป

ตัวอย่างต่อไปนี้ทั้งหมดใช้รูปภาพนี้และใส่เท็กซ์เจอร์ให้โมเดลด้วย Meshy 7 ซึ่งถูกเลือกโดย texture_model หากต้องการลองใช้รูปภาพอื่น ให้เปลี่ยน image_url หากต้องการเลือกโมเดลเท็กซ์เจอร์อื่น ดูที่ โมเดลเท็กซ์เจอร์

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 พร้อมกับ อ็อบเจ็กต์งาน เก็บ 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 ระหว่างการเรียกคำขอแต่ละครั้ง ให้รอตามจำนวนวินาทีที่ระบุไว้ใน header Retry-After

เส้นทาง (route) เดียวกันนี้ใช้ได้กับงานจากทุกเอนด์พอยต์ สำหรับระยะเวลาการประมวลผลโดยทั่วไป และควรรอนานเท่าใดก่อนที่จะยอมเลิก โปรดดู Processing times และ How long to wait

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 คุณยังสามารถวาง URL นี้ลงในเบราว์เซอร์เพื่อดาวน์โหลดไฟล์ได้เช่นกัน

รูปภาพเป็น 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

Put it all together

สคริปต์นี้จะสร้างงาน รอจนกว่าจะเสร็จสิ้น แล้วดาวน์โหลดโมเดล

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

Explore common workflows


ขั้นตอนถัดไป

  • เรียนรู้เกี่ยวกับ task object และเส้นทาง Tasks ที่ทุกเอนด์พอยต์ใช้ร่วมกัน
  • ดูรายการเอนด์พอยต์ทั้งหมดได้ใน ภาพรวม API v2
  • ตรวจสอบ ราคา, Rate limits และ ข้อผิดพลาด ก่อนนำไปใช้งานจริง
  • ชอบใช้ UI มากกว่าใช่ไหม? Developer Platform ช่วยให้คุณรันคำขอต่าง ๆ ได้ใน Playground ติดตามการใช้งานและบันทึกคำขอ รวมถึงจัดการ webhooks
  • ทำตามสูตรแบบทีละขั้นตอนได้ใน Cookbook และอ่านบทแนะนำต่าง ๆ ได้ที่ Developer Blog
  • มีข้อเสนอแนะหรือพบปัญหาใช่ไหม? เข้าร่วมคอมมูนิตี้ Discord ของ Meshy