Skip to content

最后更新:

API 参考 ​

Base URL:http://<你的服务器IP或域名>:8080

认证 ​

所有业务接口需在请求头中携带:

Header值必填
X-API-Key你的 API 密钥✅

安全提醒

不要把 API Key 写在前端代码中。应放在后端服务或 CI 流水线中使用。

异步任务流程 ​

text
POST compress   → 返回 task_id
GET tasks/{id}  → pending / processing / completed / failed
GET download    → 下载结果文件
status含义操作
pending排队中继续轮询
processing处理中继续轮询
completed完成调用 download
failed失败查看 error 字段

一、系统状态 ​

GET /api/v1/health ​

无需认证。

Response 200

json
{ "status": "healthy", "version": "2.1.0", "uptime_seconds": 3600, "active_tasks": 0, "queue_length": 0 }

GET /api/v1/capabilities ​

查询当前服务支持的能力。

Response 200

json
{
  "engines": {
    "draco":   { "available": true, "version": "…", "binary_path": "…" },
    "meshopt": { "available": true, "version": "…", "binary_path": "…" }
  },
  "formats": {
    "input":  ["glb", "gltf", "obj", "fbx", "stl", "dae", "ply"],
    "output": ["glb", "gltf", "obj", "stl", "ply"]
  },
  "license": { "authorized": true, "tier": 1, "status": "active" }
}

二、模型压缩 ​

POST /api/v1/compress ​

提交压缩任务。

Headers

Header值
Content-Typemultipart/form-data
X-API-Key你的密钥

Body (form-data)

字段类型必填说明
fileFile✅模型文件(GLB/glTF/OBJ/FBX 等)
enginestring✅draco 或 meshopt
levelinteger❌压缩级别 0-10(0 为 RAW 不压缩),默认 7。数值越大压缩率越高
position_quantization_bitsinteger❌位置精度(仅 Draco),默认 14,范围 8-24
normal_quantization_bitsinteger❌法线精度(仅 Draco),默认 10
texcoord_quantization_bitsinteger❌UV 精度(仅 Draco),默认 12
color_quantization_bitsinteger❌颜色精度(仅 Draco),默认 8
generic_quantization_bitsinteger❌通用属性精度(仅 Draco),默认 12
meshopt_compression_levelstring❌Meshopt 等级:high / medium / low,默认 high

Response 200

json
{
  "task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "pending",
  "message": "任务已提交,正在排队"
}

三、格式转换 ​

POST /api/v1/convert ​

将模型从一种格式转换为另一种。

Headers

Header值
Content-Typemultipart/form-data
X-API-Key你的密钥

Body (form-data)

字段类型必填说明
fileFile✅模型文件
target_formatstring✅glb / gltf / obj / fbx / stl / dae / ply

目标为 gltf 时输出 .zip 包(含 .gltf + .bin + 贴图)。

Response 200

json
{
  "task_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
  "status": "pending"
}

四、模型修复 ​

POST /api/v1/repair ​

自动去空节点、修法线、合并重复顶点、删退化面等。

Headers

Header值
Content-Typemultipart/form-data
X-API-Key你的密钥

Body (form-data)

字段类型必填说明
fileFile✅模型文件

Response 200

json
{
  "task_id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
  "status": "pending"
}

五、模型诊断(规划中) ​

POST /api/v1/diagnose ​

端点已预留,当前版本返回 501(功能尚未实现)。模型体检诊断目前仅在桌面版提供。


六、纹理优化 ​

POST /api/v1/textures/optimize ​

对模型贴图或单独图片进行 JPEG/WebP/PNG 压缩。

Headers

Header值
Content-Typemultipart/form-data
X-API-Key你的密钥

Body (form-data)

字段类型必填说明
fileFile✅模型文件或单独图片
formatstring✅jpeg / webp / png
qualityinteger❌质量 1-100,默认 82(JPEG/WebP);PNG 压缩级 1-9,默认 6

Response 200

json
{
  "task_id": "d4e5f6a7-b8c9-0123-defa-234567890123",
  "status": "pending"
}

POST /api/v1/textures/ktx2 ​

端点已预留,当前版本返回 501(KTX2 编码尚未实现)。KTX2 编码目前仅在桌面版提供。


七、任务管理 ​

GET /api/v1/tasks/{task_id} ​

通过 task_id 查询任务状态和进度。

Path 参数

参数类型说明
task_idstring任务唯一标识

Response 200 — 处理中

json
{
  "task_id": "a1b2c3d4-...",
  "status": "processing",
  "progress": 65,
  "created_at": "2026-08-03T10:30:00Z",
  "started_at": "2026-08-03T10:30:01Z",
  "type": "compress",
  "input_filename": "model.glb",
  "input_size_bytes": 15728640
}

Response 200 — 已完成

json
{
  "task_id": "a1b2c3d4-...",
  "status": "completed",
  "progress": 100,
  "created_at": "2026-08-03T10:30:00Z",
  "completed_at": "2026-08-03T10:30:05Z",
  "type": "compress",
  "input_filename": "model.glb",
  "input_size_bytes": 15728640,
  "output": {
    "filename": "model_optimized.glb",
    "size_bytes": 3145728,
    "compression_ratio": 0.20,
    "savings_percent": 80.0
  }
}

Response 200 — 失败

json
{
  "task_id": "a1b2c3d4-...",
  "status": "failed",
  "error": "draco_transcoder execution failed: exit code 1",
  "created_at": "2026-08-03T10:30:00Z",
  "failed_at": "2026-08-03T10:30:02Z"
}

响应字段说明

字段类型说明
task_idstring任务唯一标识
statusstringpending / processing / completed / failed
progressinteger进度 0-100
typestringcompress / convert / repair / diagnose / texture_optimize / texture_ktx2
input_filenamestring原始文件名
input_size_bytesinteger原始大小(字节)
output.filenamestring输出文件名(completed 时)
output.size_bytesinteger输出大小(字节)(completed 时)
output.compression_ratiofloat压缩比(compress/texture 类)
output.savings_percentfloat体积减少百分比(compress/texture 类)
errorstring错误原因(failed 时)
created_atstring创建时间 ISO 8601
started_atstring开始时间
completed_at / failed_atstring结束时间

GET /api/v1/tasks/{task_id}/download ​

下载处理后的结果文件。

Path 参数

参数类型说明
task_idstring已完成的任务 ID

Response 200

返回文件二进制流(Content-Type: application/octet-stream)。


八、批量处理 ​

POST /api/v1/batch/compress ​

一次提交多个文件压缩,每个独立生成子任务。

Headers

Header值
Content-Typemultipart/form-data
X-API-Key你的密钥

Body (form-data)

字段类型必填说明
filesFile[]✅多个模型文件
enginestring✅draco 或 meshopt
levelinteger❌压缩级别 1-10,默认 7

Response 200

json
{
  "batch_id": "batch-abc123",
  "total": 3,
  "tasks": [
    { "task_id": "t1-...", "filename": "model1.glb", "status": "pending" },
    { "task_id": "t2-...", "filename": "model2.fbx", "status": "pending" },
    { "task_id": "t3-...", "filename": "scene.gltf", "status": "pending" }
  ]
}

GET /api/v1/batch/{batch_id} ​

查询批次整体进度。

Path 参数

参数类型说明
batch_idstring批次唯一标识

Response 200

json
{
  "batch_id": "batch-abc123",
  "status": "processing",
  "total": 3, "completed": 1, "failed": 0,
  "tasks": [
    { "task_id": "t1-...", "filename": "model1.glb", "status": "completed" },
    { "task_id": "t2-...", "filename": "model2.fbx", "status": "processing" },
    { "task_id": "t3-...", "filename": "scene.gltf", "status": "pending" }
  ]
}

子任务可单独通过 查询任务 和 下载结果 操作。


九、授权 ​

POST /api/v1/license/verify ​

验证 License Key 是否有效。

Body (JSON)

json
{ "license_key": "xxxx-xxxx-xxxx-xxxx" }

Response 200

json
{
  "success": true,
  "message": "license valid",
  "expires_at": 1796064000
}

expires_at 为 Unix 时间戳(秒)。此端点面向管理用途。


GET /api/v1/license/info ​

查询当前授权状态。

Response 200

json
{
  "authorized": true,
  "server_fingerprint": "a1b2c3d4e5f6…",
  "status": "active",
  "license_expires_at": 1796064000,
  "tier": 1,
  "days_until_expiry": 365,
  "machine_id": "server-machine-id"
}

tier:0 = 未授权(试用限制),1/2 = 授权档位;license_expires_at 为 Unix 时间戳(秒)。


十、监控 ​

GET /api/v1/metrics ​

Prometheus 格式监控指标,可用于 Grafana 集成。

指标名含义
zipoly_requests_total请求总数
zipoly_active_tasks当前并发任务数
zipoly_queue_length队列中等待的任务数
zipoly_task_processing_duration_seconds任务处理耗时分布
zipoly_tasks_completed_total已完成任务总数
zipoly_tasks_failed_total失败任务总数
zipoly_errors_total错误总数

错误码 ​

HTTP含义典型场景
400参数错误不支持的格式、缺少必填字段
402超出授权限制文件超过当前套餐的大小/批量限制、授权过期
401未授权缺少/错误的 X-API-Key
404不存在task_id / batch_id 无效
500内部错误引擎执行失败、磁盘不足

错误响应格式

json
{ "error": "错误描述信息" }
场景示例
不支持的格式{ "error": "unsupported format: .max" }
缺少必填字段{ "error": "missing required field: engine" }
未授权{ "error": "unauthorized: missing or invalid X-API-Key header" }
超出限制{ "error": "file size 512MB exceeds limit of 500MB for current license tier" }
内部错误{ "error": "internal error: draco_transcoder execution failed" }

其他端点 ​

除上述业务端点外,服务端还提供 Web 管理后台专用的端点(配置读写 /config、事件流 /events、/auth/me、/admin/* 等),一般无需直接调用,此处不再展开。

专为 Web3D 开发者设计