快速开始

快速开始

API

API 概览认证可用模型

指南

快速开始错误处理
API

快速开始

完整的分步指南,完成您的首次 3D 生成

快速开始

5 分钟内生成您的第一个 3D 模型。

创建 API 密钥

  1. 登录您的账户
  2. 进入 设置 → API 密钥
  3. 点击 创建密钥,命名后复制密钥

创建生成任务

发送 POST 请求,附带您的图片和所选模型:

curl -X POST https://trellis2.app/api/v1/3d/generations \
  -H "Authorization: Bearer tr_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "image_url": "https://example.com/chair.jpg",
    "model": "trellis2",
    "mode": "async"
  }'
import requests

response = requests.post(
    "https://trellis2.app/api/v1/3d/generations",
    headers={
        "Authorization": "Bearer tr_your_key",
        "Content-Type": "application/json"
    },
    json={
        "image_url": "https://example.com/chair.jpg",
        "model": "trellis2",
        "mode": "async"
    }
)

task = response.json()
task_id = task["id"]
print(f"任务已创建: {task_id}")
const response = await fetch('https://trellis2.app/api/v1/3d/generations', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer tr_your_key',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    image_url: 'https://example.com/chair.jpg',
    model: 'trellis2',
    mode: 'async',
  }),
});

const task = await response.json();
console.log('任务已创建:', task.id);

轮询结果

import time

while True:
    resp = requests.get(
        f"https://trellis2.app/api/v1/tasks/{task_id}",
        headers={"Authorization": "Bearer tr_your_key"}
    )
    data = resp.json()

    if data["status"] == "completed":
        print(f"模型 URL: {data['data']['model_url']}")
        break
    elif data["status"] == "failed":
        print(f"错误: {data['error']['message']}")
        break

    print(f"进度: {data.get('progress', 0)}%")
    time.sleep(3)
while (true) {
  const resp = await fetch(`https://trellis2.app/api/v1/tasks/${task.id}`, {
    headers: { 'Authorization': 'Bearer tr_your_key' },
  });
  const data = await resp.json();

  if (data.status === 'completed') {
    console.log('模型 URL:', data.data.model_url);
    break;
  } else if (data.status === 'failed') {
    console.error('错误:', data.error.message);
    break;
  }

  console.log(`进度: ${data.progress}%`);
  await new Promise((r) => setTimeout(r, 3000));
}

下载您的模型

完成的任务会返回一个 model_url,指向可下载的 GLB 文件:

curl -O https://r2.../model.glb

就这样!您已经成功从图片生成了 3D 模型。查看 可用模型 了解所有选项。

可用模型

通过 API 可用的 3D 生成模型

错误处理

如何处理 API 错误和边界情况

目录

快速开始
创建 API 密钥
创建生成任务
轮询结果
下载您的模型