# Tripo-3D-Animation 调用指南

### 0. 简介与支持的模型 ID

**Tripo 动画重定向**：把一套**预设动画**应用到**已绑骨**的 3D 模型上，输出带动画的模型文件
（GLB 或 FBX），可直接放进 Web 页面、游戏引擎或 DCC 工具里播放。

| 模型 ID | 说明 | 状态 |
| :--- | :--- | :--- |
| `tripo-3d-animation` | Tripo 动画重定向，输入已绑骨模型 + 预设动画，输出带动画的模型文件 | 已支持（本文档的接口、参数、响应均以它为准） |

> [!IMPORTANT]
> 本接口与「Tripo-3D 模型生成」「Tripo-3D-Rigging-Check」「Tripo-3D-Rigging」**共用同一对入口**
> （`POST /v1/3d/generations` 与 `GET /v1/3d/generations/{task_id}`），只靠 `model` 字段取值区分能力。
> 模型名大小写不敏感，网关会统一归一化为小写后转发上游。

> [!WARNING]
> 本接口的输入必须是**已绑骨（rigged）**的模型。把未绑骨的裸模型直接送进来会失败——
> 请先用 `tripo-3d-rigging` 完成绑骨（不确定能不能绑骨可先用 `tripo-3d-rigging-check` 探一下）。

---

### 1. 接口一览

| 能力 | 路径 | 请求方式 | 说明 |
| :--- | :--- | :--- | :--- |
| 提交动画任务 | `/v1/3d/generations` | `POST` | 提交已绑骨模型与预设动画，立即返回任务 ID |
| 查询动画结果 | `/v1/3d/generations/{task_id}` | `GET` | 轮询任务状态，完成后返回带动画的模型文件地址 |
| 取消任务 | `/v1/3d/generations/{task_id}` | `DELETE` | 非终态任务可尝试取消 |

基础调用地址：

```bash
https://newapi.huizhitv.com
```

鉴权（三选一，与本站其它 OpenAI 兼容接口一致）：

```http
Authorization: Bearer sk-your_token_string_here
```

```bash
https://newapi.huizhitv.com/v1/3d/generations?key=sk-your_token_string_here
```

---

### 2. 提交动画任务

* **路径**: `/v1/3d/generations`
* **请求方式**: `POST`
* **Content-Type**: `application/json`

#### 2.1 请求参数

| 参数 | 类型 | 必填 | 说明 |
| :--- | :--- | :--- | :--- |
| `model` | string | 是 | 模型 ID，本文档固定为 **`tripo-3d-animation`** |
| `input` | string | 是 | **已绑骨模型标识**，即上一步绑骨任务响应里的 **`output.task_id`** |
| `animation` | string | 条件必选 | 单个预设动画标识符，如 `preset:walk`。**与 `animations` 互斥，二选一** |
| `animations` | string[] | 条件必选 | 多个预设动画标识符数组，如 `["preset:walk","preset:run"]`。**与 `animation` 互斥** |
| `out_format` | string | 否 | 输出格式：`glb`（二进制 glTF，适用于 Web）/ `fbx`（适用于 DCC 工具与游戏引擎），默认 `glb` |
| `bake_animation` | boolean | 否 | 把动画烘焙进模型。**仅对 `glb` 输出有效**，默认 `true` |
| `export_with_geometry` | boolean | 否 | 导出时包含几何体，默认 `true`。传 `false` 只导出骨骼与动画数据 |
| `animate_in_place` | boolean | 否 | 原地播放动画、不产生位移，默认 `false` |

> [!IMPORTANT]
> `animation` 与 `animations` **必须且只能填其中一个**：
> 两个都不填或同时都填，上游会判定为参数错误。只要一个动画用 `animation`，
> 想把多套动作合进同一个文件（如走 + 跑）用 `animations`。

> [!IMPORTANT]
> **`input` 怎么拿**：先完成绑骨（`tripo-3d-rigging`），在绑骨任务的轮询响应里取
> **`output.task_id`** 这个值，原样填进本接口的 `input`。
>
> ```json
> // GET /v1/3d/generations/{绑骨任务ID} 的响应
> {
>   "status": "completed",
>   "output": { "task_id": "e75f13f2-8681-4d93-8bb4-e19629cb304a", ... },
>   "data": [{ "url": "https://.../rig/output/....glb?..." }]
> }
> //                    ↑ 这个 task_id 就是本接口要的 input
> ```
>
> ⚠️ **不要填别的**，以下三种写法都会被上游拒绝：
>
> | 错误写法 | 上游报错 |
> | :--- | :--- |
> | 绑骨产物的文件 URL（`https://.../rig/output/xxx.glb?...`） | `FailedOperation.JobNotExist` 任务不存在 |
> | 产物文件名里的 UUID（`5e13212b-18b5-...`） | `The task is not found` |
> | 绑骨任务的站点任务 ID（形如 `1503...` 的数字串） | 同上 |

> [!NOTE]
> 本接口**不接受 `prompt`**：动作由预设动画标识符指定，传文字描述不会参与。

#### 2.2 预设动画标识符

标识符统一以 `preset:` 开头。按骨骼类型分为三组，请与模型实际的骨骼类型匹配，
例如在四足模型上用双足动作会得到异常姿态。

**通用简写（不分骨骼前缀）**

| 分类 | 标识符 |
| :--- | :--- |
| 双足 | `preset:idle`、`preset:walk`、`preset:run`、`preset:dive`、`preset:climb`、`preset:jump`、`preset:slash`、`preset:shoot`、`preset:hurt`、`preset:fall`、`preset:turn` |
| 四足 | `preset:quadruped:walk` |
| 六足 / 八足 | `preset:hexapod:walk`、`preset:octopod:walk` |
| 蛇形 / 水生 | `preset:serpentine:march`、`preset:aquatic:march` |

**双足完整动作表（`preset:biped:*`）**

|  |  |  |  |
| :--- | :--- | :--- | :--- |
| `preset:biped:afraid` | `preset:biped:agree` | `preset:biped:angry_01` | `preset:biped:angry_02` |
| `preset:biped:angry_03` | `preset:biped:basketball_shot` | `preset:biped:bow` | `preset:biped:box_01` |
| `preset:biped:box_02` | `preset:biped:box_03` | `preset:biped:cast_a_spell` | `preset:biped:cheer` |
| `preset:biped:chop` | `preset:biped:clap` | `preset:biped:climb` | `preset:biped:complain_01` |
| `preset:biped:complain_02` | `preset:biped:cross_body_crunch` | `preset:biped:crossover_dribble` | `preset:biped:cry` |
| `preset:biped:dance_01` | `preset:biped:dance_02` | `preset:biped:dance_03` | `preset:biped:dance_04` |
| `preset:biped:dance_05` | `preset:biped:dance_06` | `preset:biped:defeat_02` | `preset:biped:defeat_03` |
| `preset:biped:depressed` | `preset:biped:dig` | `preset:biped:dive` | `preset:biped:dribble` |
| `preset:biped:fall` | `preset:biped:fire` | `preset:biped:flee_01` | `preset:biped:flee_02` |
| `preset:biped:flip` | `preset:biped:fold_arms` | `preset:biped:football_catch` | `preset:biped:football_save` |
| `preset:biped:football_pass` | `preset:biped:freaky` | `preset:biped:frightened` | `preset:biped:front_kick_01` |
| `preset:biped:front_kick_02` | `preset:biped:frustrated_01` | `preset:biped:frustrated_02` | `preset:biped:golf` |
| `preset:biped:greet_01` | `preset:biped:greet_02` | `preset:biped:greet_03` | `preset:biped:greet_04` |
| `preset:biped:heart_pose` | `preset:biped:hit_to_body_01` | `preset:biped:hit_to_body_02` | `preset:biped:hit_to_head` |
| `preset:biped:hit_to_side` | `preset:biped:hit_to_stomach` | `preset:biped:hug` | `preset:biped:hurt` |
| `preset:biped:idle` | `preset:biped:jump_down` | `preset:biped:jump` | `preset:biped:jump_rope_01` |
| `preset:biped:jump_rope_02` | `preset:biped:laugh_01` | `preset:biped:laugh_02` | `preset:biped:lift_heavy` |
| `preset:biped:look_around` | `preset:biped:make_a_call_01` | `preset:biped:make_a_call_02` | `preset:biped:pitch_baseball` |
| `preset:biped:play_mobile_game` | `preset:biped:play_video_game` | `preset:biped:press-up` | `preset:biped:run_upstairs` |
| `preset:biped:run` | `preset:biped:scared_01` | `preset:biped:scared_02` | `preset:biped:scratch` |
| `preset:biped:shoot` | `preset:biped:shovel` | `preset:biped:sing_01` | `preset:biped:sing_02` |
| `preset:biped:sing_03` | `preset:biped:sing_04` | `preset:biped:sit` | `preset:biped:slash` |
| `preset:biped:sob` | `preset:biped:standing_relax` | `preset:biped:surf` | `preset:biped:swagger` |
| `preset:biped:swim` | `preset:biped:turn` | `preset:biped:victory_celebration` | `preset:biped:volleyball` |
| `preset:biped:wait` | `preset:biped:walk` | `preset:biped:warm_up` | `preset:biped:wave_goodbye_01` |
| `preset:biped:wave_goodbye_02` | | | |

#### 2.3 调用示例：单个动画

```bash
curl -X POST https://newapi.huizhitv.com/v1/3d/generations \
  -H "Authorization: Bearer sk-your_token_string_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tripo-3d-animation",
    "input": "e75f13f2-8681-4d93-8bb4-e19629cb304a",
    "animation": "preset:walk"
  }'
```

#### 2.4 调用示例：多个动画 + FBX 输出

```bash
curl -X POST https://newapi.huizhitv.com/v1/3d/generations \
  -H "Authorization: Bearer sk-your_token_string_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tripo-3d-animation",
    "input": "e75f13f2-8681-4d93-8bb4-e19629cb304a",
    "animations": ["preset:walk", "preset:run"],
    "out_format": "fbx",
    "animate_in_place": true
  }'
```

#### 2.5 提交响应

任务是异步的，`POST` 立即返回，不会等待动画生成结束：

```json
{
  "id": "1503685330012345678",
  "object": "3d.generation",
  "status": "pending",
  "created": 1791895818
}
```

| 字段 | 说明 |
| :--- | :--- |
| `id` | 任务 ID，轮询与取消时用这个值（**有效期 24 小时**） |
| `object` | 固定为 `3d.generation` |
| `status` | 提交成功固定为 `pending` |
| `created` | 任务创建时间戳（Unix 秒） |

---

### 3. 查询动画结果

* **路径**: `/v1/3d/generations/{task_id}`
* **请求方式**: `GET`
* `{task_id}` 为第 2 步响应里的 `id`

```bash
curl https://newapi.huizhitv.com/v1/3d/generations/1503685330012345678 \
  -H "Authorization: Bearer sk-your_token_string_here"
```

#### 3.1 处理中

```json
{
  "id": "1503685330012345678",
  "object": "3d.generation",
  "status": "in_progress",
  "created": 1791895818
}
```

#### 3.2 完成

```json
{
  "id": "1503685330012345678",
  "object": "3d.generation",
  "status": "completed",
  "created": 1791895818,
  "data": [
    {
      "url": "https://vcg-prod-1258344699.cos.ap-guangzhou.tencentcos.cn/3dtripo/anim/output/1501334065/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.glb?q-sign-algorithm=sha1&q-ak=...&q-sign-time=...&q-key-time=...&q-header-list=host&q-url-param-list=&q-signature=..."
    }
  ]
}
```

| 字段 | 说明 |
| :--- | :--- |
| `status` | `queued` / `in_progress` / `completed` / `failed` |
| `data[].url` | 带动画的模型文件地址，格式由入参 `out_format` 决定（默认 **GLB**） |

> [!IMPORTANT]
> `data[].url` 是带临时签名（`q-sign-time`）的对象存储直链，**有效期约 24 小时**，
> 请在有效期内下载或转存到自己的存储空间。签名过期后再访问会返回 403。
> 若 `out_format` 传了 `fbx`，这里返回的就是 `.fbx` 文件链接。

#### 3.3 失败

```json
{
  "id": "1503685330012345678",
  "object": "3d.generation",
  "status": "failed",
  "created": 1791895818
}
```

---

### 4. 完整示例（curl）

下面是一段可直接运行的 Shell 脚本，串起完整四步：**提交动画 → 轮询到终态 → 取回文件链接 → 下载保存**。
依赖 `curl` 与 `jq`（用于解析 JSON，macOS 可 `brew install jq`，Debian/Ubuntu 可 `apt install jq`）。

```bash
#!/usr/bin/env bash
set -u

BASE="https://newapi.huizhitv.com"
KEY="sk-your_token_string_here"
RIGGED_MODEL="e75f13f2-8681-4d93-8bb4-e19629cb304a"   # 绑骨响应里的 output.task_id

# 1. 提交动画重定向（单动画用 animation，多动画改用 animations 数组）
SUBMIT=$(curl -s -X POST "$BASE/v1/3d/generations" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"model\": \"tripo-3d-animation\",
    \"input\": \"$RIGGED_MODEL\",
    \"animation\": \"preset:walk\",
    \"out_format\": \"glb\",
    \"bake_animation\": true,
    \"animate_in_place\": false
  }")

TASK_ID=$(echo "$SUBMIT" | jq -r '.id')
STATUS=$(echo "$SUBMIT" | jq -r '.status')
echo "已提交: task_id=$TASK_ID status=$STATUS"

# 2. 轮询直到终态（completed / failed）
RES=""
while true; do
  RES=$(curl -s "$BASE/v1/3d/generations/$TASK_ID" \
    -H "Authorization: Bearer $KEY")
  STATUS=$(echo "$RES" | jq -r '.status')
  [ "$STATUS" = "completed" ] || [ "$STATUS" = "failed" ] && break
  echo "处理中: $STATUS"
  sleep 3
done

# 3. 取回带动画的模型并下载（链接有效期约 24 小时）
if [ "$STATUS" = "completed" ]; then
  URL=$(echo "$RES" | jq -r '.data[0].url')
  echo "动画生成完成: $URL"
  curl -sL "$URL" -o model_walk.glb
  ls -lh model_walk.glb
else
  echo "动画生成失败:"
  echo "$RES" | jq '.'
fi
```

> [!NOTE]
> * 要一次合成多套动作，把第 1 步的 `"animation"` 换成
>   `"animations": ["preset:walk","preset:run"]`（两者不能同时出现）。
> * `out_format` 传 `fbx` 时，第 3 步下载的文件后缀请相应改成 `.fbx`，
>   且 `bake_animation` 对 fbx **不生效**。
> * 不想装 `jq` 也可以：把 `echo "$RES" | jq -r '.status'` 换成 `grep -o '"status":"[^"]*"'`
>   自行取字段，或直接肉眼看 `curl -s ... | python -m json.tool` 的输出。

---

### 5. 调用限制

* **并发限制**：默认提供 **1 个并发**，即同一时刻仅处理 1 个任务。上一个任务尚未完成时
  提交下一个会被拒绝，请在前一个任务返回终态（`completed` / `failed`）后再提交。
* **任务有效期**：任务 ID 有效期 **24 小时**，过期后无法再查询，请在该窗口内取走结果。
* **计费口径**：仅在任务成功（返回 `completed`）时计费；处理中或失败不计费。
  上游终态响应会回传本次消耗的积分 `credits_consumed`（实测一次动画重定向为 **10 Credit**），
  站点按每 Credit 费率换算成金额扣费；实际数值以「任务日志」里该条记录为准。

---

### 6. 常见错误

| 现象 | 原因 | 处理 |
| :--- | :--- | :--- |
| `model does not exist` / 找不到模型 | `model` 字段值不匹配 | 确认填的是 `tripo-3d-animation`（大小写不敏感） |
| `input 不能为空` / 参数缺失 | 请求体里没带 `input` | 必填 `input`，值为绑骨响应里的 `output.task_id` |
| `FailedOperation.JobNotExist` 任务不存在 | 把产物文件 URL 当成 `input` 传了 | 改传 `output.task_id`，不要传 `.glb` 链接 |
| `The task is not found` | `input` 填了文件名 UUID 或站点任务 ID | 同上，只能填绑骨响应的 `output.task_id` |
| 提示模型未绑骨 / 动画应用失败 | 送进来的模型没有骨骼 | 先用 `tripo-3d-rigging` 绑骨；不确定可先用 `tripo-3d-rigging-check` 检查 |
| 动画参数报错 / 互斥错误 | `animation` 与 `animations` 同时传了或都没传 | 二选一：单个传 `animation`，多个传 `animations` 数组 |
| 动作标识符无效 | 拼错或用了不在枚举内的值 | 只能用本文档第 2.2 节列出的 `preset:` 标识符 |
| 姿态扭曲、动作对不上 | 动画骨骼类型与模型骨骼类型不匹配 | 四足模型用 `preset:quadruped:*`，别用 biped 动作 |
| `bake_animation` 改了没效果 | 输出格式是 fbx | 该参数**仅对 glb 有效** |
| 提交返回并发受限 | 上一个任务还没跑完 | 轮询等待上一个任务到 `completed` / `failed` 后再提交 |
| `data[].url` 下载 403 | 临时签名过期（约 24 小时） | 及时转存；已过期需重新生成 |
| 查询一直 `in_progress` | 上游排队中 | 继续轮询；若长时间不动可在「任务日志」里对该记录手动同步确认最终状态 |
| 401 / 403 | 令牌无效或没有该模型权限 | 检查 API 密钥与该令牌允许调用的模型列表 |

---

### 7. 与生成 / 绑骨的对照

| 项目 | 模型生成 | 绑骨前检查 | 自动绑骨 | 动画重定向（本文档） |
| :--- | :--- | :--- | :--- | :--- |
| 模型 ID | `tripo-3d-3.1` / `tripo-3d-p1` | `tripo-3d-rigging-check` | `tripo-3d-rigging` | `tripo-3d-animation` |
| 作用 | 文/图生 3D | 判断能否绑骨 | 加骨骼绑定 | 把预设动画套上去 |
| 主要入参 | `prompt` / `image` | `input`（模型直链） | `input` + `rig_type` 等 | `input` + `animation` / `animations` |
| 输入形态 | 文字或图片 | 模型文件 | 模型文件 | **已绑骨模型标识**（绑骨的 `output.task_id`） |
| 是否有产物文件 | 有 | 无，只有 `output` 结论 | 有 | 有 |
| 结果字段 | `data[].url` | `output.riggable` / `output.rig_type` | `data[].url` + `output.task_id` | `data[].url` |

推荐的完整链路：**生成模型**（`tripo-3d-3.1` / `tripo-3d-p1`）→ **检查**（`tripo-3d-rigging-check`）
→ **绑骨**（`tripo-3d-rigging`，把检查拿到的 `rig_type` 传进去）→ **加动画**（`tripo-3d-animation`，
`input` 填绑骨响应里的 `output.task_id`）。
