
这篇 Hunyuan 3D 3.6 API 指南带你从拿到 API 密钥一路走到下载 GLB。所有请求都发往同一个端点,使用两个模型 ID 之一:hunyuan-3d/v3.6/text-to-3d 或 hunyuan-3d/v3.6/image-to-3d,并以异步任务方式运行。下文给出可直接使用的 JSON 请求体,覆盖文生 3D、图生 3D、最多 8 个视图的多视图输入、PBR、面数、贴图尺寸和纯几何模式,并附 Python 和 Node 的轮询代码。这些配置都可以先在 Hunyuan 3D 3.6 模型页的 Playground 里试一试。
Hunyuan 3D 3.6 API 调用流程
- 向
POST https://api.poyo.ai/api/generate/submit发送请求,带上Authorization: Bearer $POYO_API_KEY,JSON 请求体包含model、input,以及可选的顶层callback_url。 - 响应返回
data.task_id,状态为not_started。提交成功不等于模型已生成。 - 轮询
GET https://api.poyo.ai/api/generate/status/{task_id},直到status变为finished或failed,或者等待 webhook。 - 读取
data.files。先是 GLB(file_type: "3d"),带贴图任务接着是 OBJ ZIP(file_type: "3d",.zip),最后是 PNG 预览图(file_type: "image")。
每个响应都带有业务 code。除了 HTTP 状态码,也要检查它:部分校验错误会返回 HTTP 200,但响应体里是 code: 400。
用 cURL 做文生 3D
curl https://api.poyo.ai/api/generate/submit \
-H "Authorization: Bearer $POYO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "hunyuan-3d/v3.6/text-to-3d",
"callback_url": "https://your-domain.com/callback",
"input": {
"prompt": "A battle-worn dwarf blacksmith in a layered leather apron over chainmail, riveted steel pauldrons, a braided beard with iron rings, holding a forging hammer in one hand",
"enable_pbr": true
}
}'
只传 prompt 和 enable_pbr,就能按默认值得到带贴图的模型:目标 2,000,000 面、4K JPEG 贴图,外加 metallic、roughness 和 normal 贴图。提示词里描述主体、部件、材质和颜色即可,长度为 1 到 1,024 个字符。
然后查询任务:
curl https://api.poyo.ai/api/generate/status/YOUR_TASK_ID \
-H "Authorization: Bearer $POYO_API_KEY"
每种输入模式的 JSON 请求体
风格化文生 3D。 style 仅用于文生 3D:qinghuaci(青花瓷)、china_style、sculpture、cartoon 或 cyberpunk。不传则按提示词生成。
{
"model": "hunyuan-3d/v3.6/text-to-3d",
"input": {
"prompt": "A round teapot with a dragon-shaped spout, a curled handle and a lid knob shaped like a lotus bud",
"style": "qinghuaci",
"enable_pbr": true,
"texture_format": "png"
}
}
单张正面图生 3D。 image_urls 只能放一张图:JPG、PNG 或 WEBP,每边 128 到 5000 px,小于 10 MB,且是公开 URL。请使用干净的正面图,物体完整入画,背景纯色。
{
"model": "hunyuan-3d/v3.6/image-to-3d",
"input": {
"image_urls": ["https://storage.poyo.ai/models/hunyuan-3d-3-6/examples/input-steampunk-owl-front-8ab04096913b.png"],
"enable_pbr": true
}
}
加上 "bake_lighting": true 可以把照片的光照和阴影保留在贴图里。默认输出无光照的 albedo 贴图,方便在引擎里重新打光。
多视图图生 3D,最多 8 个视图。 正面图仍放在 image_urls,再添加七个命名视图字段中的任意几个,每个字段一张 JPG 或 PNG。所有视图必须是同一个物体。
{
"model": "hunyuan-3d/v3.6/image-to-3d",
"input": {
"image_urls": ["https://example.com/owl-front.png"],
"back_image_url": "https://example.com/owl-back.png",
"left_image_url": "https://example.com/owl-left.png",
"right_image_url": "https://example.com/owl-right.png",
"top_image_url": "https://example.com/owl-top.png",
"bottom_image_url": "https://example.com/owl-bottom.png",
"left_front_image_url": "https://example.com/owl-left-front.png",
"right_front_image_url": "https://example.com/owl-right-front.png",
"enable_pbr": true,
"ao_strength": 0.5
}
}
只要多加一个视图,任务就会切换为多视图生成并按对应价格计费。ao_strength(0 到 1,默认 0)控制环境光遮蔽,只对带贴图的多视图任务生效。
面数与贴图尺寸。 face_count 取值 1,000 到 2,000,000。默认情况下模型把它当作目标值,并根据物体自行调整;face_strict_mode: true 会强制输出精确面数。texture_resolution 可选 2k、4k 或 8k,seamless_texture: true 则以牺牲部分贴图细节换取更少接缝。
{
"model": "hunyuan-3d/v3.6/image-to-3d",
"input": {
"image_urls": ["https://example.com/sneaker-front.png"],
"face_count": 200000,
"face_strict_mode": true,
"texture_resolution": "2k",
"texture_format": "webp",
"enable_pbr": true
}
}
这套参数适合网页查看器和 AR,这类场景里文件大小比最后那点细节更重要。
纯几何。 generate_type: "Geometry" 返回无贴图白模:一个 GLB 加一张 PNG 预览图,没有 OBJ ZIP。这类任务会忽略贴图选项,所以不要传。
{
"model": "hunyuan-3d/v3.6/text-to-3d",
"input": {
"prompt": "A carved wooden chess knight with a flowing mane, flared nostrils and a ringed round base",
"generate_type": "Geometry",
"face_count": 300000,
"face_strict_mode": true
}
}
Python 限时轮询循环
在装好 requests 的后端运行这段代码。它会检查 HTTP 错误和业务错误,任务失败即停止,30 分钟后放弃。超时的意思是"稍后再查同一个任务 ID",而不是"重新提交":再提交一次就是再计费一次生成。
import os
import time
import requests
BASE = "https://api.poyo.ai"
s = requests.Session()
s.headers["Authorization"] = "Bearer " + os.environ["POYO_API_KEY"]
def checked(resp):
resp.raise_for_status()
body = resp.json()
if body.get("code") != 200:
raise RuntimeError(f"PoYo error {body.get('code')}: {body.get('error')}")
return body["data"]
task = checked(s.post(BASE + "/api/generate/submit", json={
"model": "hunyuan-3d/v3.6/image-to-3d",
"input": {
"image_urls": ["https://example.com/owl-front.png"],
"enable_pbr": True,
},
}, timeout=60))
task_id = task["task_id"]
print("task", task_id, flush=True)
deadline = time.monotonic() + 30 * 60
while time.monotonic() < deadline:
task = checked(s.get(f"{BASE}/api/generate/status/{task_id}", timeout=60))
if task["status"] == "failed":
raise RuntimeError(task.get("error_message") or "generation failed")
if task["status"] == "finished":
break
time.sleep(15)
else:
raise TimeoutError("still running, poll again later: " + task_id)
print("charged", task.get("credits_amount"), "credits")
for f in task["files"]:
name = f["file_url"].rsplit("/", 1)[-1]
with s.get(f["file_url"], stream=True, timeout=300) as r:
r.raise_for_status()
with open(name, "wb") as out:
for chunk in r.iter_content(1 << 20):
out.write(chunk)
print("saved", f["file_type"], name)
下载时请使用流式传输。在上线当天的测试中,带贴图的 GLB 分别为 72 MB 和 82 MB,OBJ ZIP 为 49 MB 和 55 MB。
Node 中的同一流程
Node 18 或更高版本,无需依赖:
const BASE = "https://api.poyo.ai";
const headers = {
Authorization: `Bearer ${process.env.POYO_API_KEY}`,
"Content-Type": "application/json",
};
async function call(path, init = {}) {
const res = await fetch(BASE + path, { ...init, headers });
const body = await res.json();
if (!res.ok || body.code !== 200) {
throw new Error(`PoYo error ${body.code}: ${JSON.stringify(body.error)}`);
}
return body.data;
}
const { task_id } = await call("/api/generate/submit", {
method: "POST",
body: JSON.stringify({
model: "hunyuan-3d/v3.6/text-to-3d",
input: {
prompt: "An armored knight with a long cape, a kite shield and a sword",
enable_pbr: true,
},
}),
});
const deadline = Date.now() + 30 * 60 * 1000;
let task;
while (Date.now() < deadline) {
task = await call(`/api/generate/status/${task_id}`);
if (task.status === "failed") throw new Error(task.error_message);
if (task.status === "finished") break;
await new Promise((r) => setTimeout(r, 15000));
}
if (task?.status !== "finished") throw new Error(`poll again later: ${task_id}`);
const glb = task.files.find((f) => f.file_url.endsWith(".glb"));
console.log(glb.file_url);
生产环境建议使用 callback_url。任务进入 finished 或 failed 后,PoYo 会把任务数据 POST 到该地址,并在 X-Webhook-Signature 中附上 HMAC-SHA256 签名;签名规则和密钥端点见 3D webhook 文档。
校验规则与需要处理的错误
| 提交前检查 | 原因 |
|---|---|
prompt 为 1 到 1,024 个字符,不能全是空白 | 文生 3D 必填 |
image_urls 中只能有一个 URL | 额外图片要放在命名视图字段里,而不是数组里 |
| 视图图片为 JPG 或 PNG,128 到 5000 px | 只有正面图接受 WEBP |
face_count 为 1,000 到 2,000,000 的整数 | 超出范围会被拒绝 |
图生 3D 不传 style,文生 3D 不传视图字段 | 字段因模型而异;未知字段会被拒绝 |
code | 处理方式 |
|---|---|
| 400 | 修正请求体;不要原样重试 |
| 401 | 检查 API 密钥 |
| 402 | 充值积分;本次未生成任何内容 |
| 429 | 退避后重新提交 |
| 500、502、503 | 退避重试;如果已返回 task_id,请轮询它而不是重新提交 |
加载结果
GLB 可直接在 three.js、Blender、Unity(配合 glTF 导入器)和大多数网页查看器中打开;OBJ ZIP 内含 OBJ、MTL 和贴图,适合偏好 OBJ 的工具。在我们的测试中,纯几何 GLB 有 1,999,996 个三角形且没有顶点法线,所以着色前请在 three.js 中调用 geometry.computeVertexNormals(),或在 DCC 工具里重新计算法线。
第一笔账单怎么算
价格按每次生成固定收取,由模型 ID、generate_type 以及是否带视图字段决定。1 积分 = $0.005。
| 你的请求 | 积分 | 美元 |
|---|---|---|
| 文生 3D,带贴图 | 400 | $2.00 |
文生 3D,Geometry | 160 | $0.80 |
| 图生 3D,单视图,带贴图 | 280 | $1.40 |
图生 3D,单视图,Geometry | 120 | $0.60 |
| 图生 3D,加额外视图,带贴图 | 400 | $2.00 |
图生 3D,加额外视图,Geometry | 160 | $0.80 |
enable_pbr、texture_resolution: "8k" 和自定义 face_count 都不会提高价格。状态响应会在 credits_amount 中给出扣费。我们上线当天的三个任务分别扣了 400、280 和 160 积分,与上表一致。批量预算和与其他 3D 模型的对比,请看 Hunyuan 3D 3.6 API 价格指南。想先了解模型概况和上线当天的结果,可以从 Hunyuan 3D 3.6 API 概览开始。如果需要一张干净的正面图作为起点,可以用同一个 API 密钥调用 GPT Image 2.6 这类图像模型来生成。
常见问题
如何用 Python 调用 Hunyuan 3D 3.6 API?
带上 Bearer 密钥,把 JSON 请求体 POST 到 https://api.poyo.ai/api/generate/submit,保存 data.task_id,然后轮询 /api/generate/status/{task_id} 直到 finished,如上面的循环所示。
如何向 Hunyuan 3D 3.6 API 发送多个视图?
正面图放在 image_urls,其他角度各占一个字段:back_image_url、left_image_url、right_image_url、top_image_url、bottom_image_url、left_front_image_url、right_front_image_url。合计最多 8 张图。
如何从 Hunyuan 3D 3.6 API 获得 PBR 材质?
在 Normal(带贴图)任务上设置 enable_pbr: true,即可免费获得 metallic、roughness 和 normal 贴图。
如何减小 Hunyuan 3D 3.6 API 模型的文件大小?
降低 face_count(需要精确面数时加 face_strict_mode: true),并使用 texture_resolution: "2k"。默认是 2,000,000 面。
Hunyuan 3D 3.6 API 会返回 FBX 或 STL 吗? 在 PoYo 上不会。任务返回 GLB、带贴图模型的 OBJ ZIP 和 PNG 预览图;其他格式请在你自己的流程中转换。
为什么我的 Hunyuan 3D 3.6 API 请求返回 code 400?
通常是字段用错了模型 ID(比如在图生 3D 上传 style)、image_urls 里放了不止一个 URL,或者取值超出范围。阅读 error.message,修正请求体后再提交。